Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D request
#11
would some body just make it though?
Reply
#12
Say thank you. Tongue

Code:
DEFINT A-Z

' Read in points that make up the lines    
TYPE LineType
    x1 AS INTEGER
    y1 AS INTEGER
    z1 AS INTEGER
    x2 AS INTEGER
    y2 AS INTEGER
    z2 AS INTEGER
END TYPE

READ NumLines
DIM Points(1 TO NumLines) AS LineType

FOR i = 1 TO NumLines
  READ Points(i).x1
  READ Points(i).y1
  READ Points(i).z1
  READ Points(i).x2
  READ Points(i).y2
  READ Points(i).z2
NEXT


' Generate sine/cosine lookup table
DIM Cosine(360) AS SINGLE
DIM Sine(360) AS SINGLE

FOR i = 0 TO 359
  Cosine(i) = COS(i * 3.14159265# / 180)
  Sine(i) = SIN(i * 3.14159265# / 180)
NEXT


' View Distance
Distance = -5
' Coordinate / Distance multiplier (for smoother animation...)
Multiplier = 1000

' Screen size
MidX = 320 / 2
MidY = 200 / 2

SCREEN 7, , 1, 0
DO
  FOR AngleX = 0 TO 359
    CLS

    ' Draw each line
    FOR i = 1 TO NumLines
    
      ' Rotate point 1 around the X axis
      x1 = Points(i).x1 * Multiplier
      y1 = Points(i).y1 * Multiplier
      z1 = Points(i).z1 * Multiplier
      y1t = INT(y1 * Cosine(AngleX) - z1 * Sine(AngleX))
      z1 = INT(y1 * Sine(AngleX) + z1 * Cosine(AngleX))
      y1 = y1t

      ' Rotate point 2 around the X axis
      x2 = Points(i).x2 * Multiplier
      y2 = Points(i).y2 * Multiplier
      z2 = Points(i).z2 * Multiplier
      y2t = INT(y2 * Cosine(AngleX) - z2 * Sine(AngleX))
      z2 = INT(y2 * Sine(AngleX) + z2 * Cosine(AngleX))
      y2 = y2t

      ' Project line onto screen
      z1 = z1 - Distance * Multiplier
      z2 = z2 - Distance * Multiplier
      IF z1 > 1 AND z2 > 1 THEN
        px1 = x1 / z1 * 256 + MidX
        py1 = y1 / z1 * 256 + MidY
        px2 = x2 / z2 * 256 + MidX
        py2 = y2 / z2 * 256 + MidY
        LINE (px1, py1)-(px2, py2), 15
      END IF
    NEXT

    PCOPY 1, 0
    IF INKEY$ <> "" THEN END

  NEXT
LOOP

END

' Number of lines total
DATA 12

' Data format is start x,y,z   end x,y,z

' Top
DATA -1, 1, 1,   1, 1, 1
DATA -1, 1, 1,  -1,-1, 1
DATA -1,-1, 1,   1,-1, 1
DATA  1,-1, 1,   1, 1, 1

' Sides
DATA  1, 1, 1,   1, 1,-1
DATA -1, 1, 1,  -1, 1,-1
DATA  1,-1, 1,   1,-1,-1
DATA -1,-1, 1,  -1,-1,-1

' Bottom
DATA -1, 1,-1,   1, 1,-1
DATA -1, 1,-1,  -1,-1,-1
DATA -1,-1,-1,   1,-1,-1
DATA  1,-1,-1,   1, 1,-1

Highly unoptimized (rotates 2x points needed, extra multiplication), X-axis rotation only. Although adding other axis is easy...
Reply
#13
thank you. Big Grin
how do you get a cube out of using only one LINE command?
Reply
#14
There's just one line command... inside a LOOP, so it draws as many lines as a cube has.

Code:
FOR i = 1 TO NumLines
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
ok, i'll look into it more i guess.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)