Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
the amazing cube!
#1
ok..now i'm just wasting space..

but its a good example for the "absolute" beginner...

Code:
'screen mode
screen 13

'type, its kinda like sayin integer, its our own kindof type
type cubecorner
   x as integer
   y as integer
end type

'c1 - c8 is a type of cube corner
dim as cubecorner c1,c2,c3,c4,c5,c6,c7,c8

'coordinates for cube corners
c1.x = 160
c1.y = 50
c2.x = 190
c2.y = c1.y
c3.x = c1.x
c3.y = 80
c4.x = c2.x
c4.y = c3.y
c5.x = 175
c5.y = 65
c6.x = c5.x
c6.y = 95
c7.x = 145
c7.y = c6.y
c8.x = c7.x
c8.y = c5.y

'horizontal lines for cube (x)
line (c1.x,c1.y)-(c2.x,c2.y),4
line (c3.x,c3.y)-(c4.x,c4.y),4
line (c6.x,c6.y)-(c7.x,c7.y),4
line (c5.x,c5.y)-(c8.x,c8.y),4

'verticle lines for cube (y)
line (c1.x,c1.y)-(c3.x,c3.y),4
line (c2.x,c2.y)-(c4.x,c4.y),4
line (c5.x,c5.y)-(c6.x,c6.y),4
line (c8.x,c8.y)-(c7.x,c7.y),4

'slanted lines (z)
line (c1.x,c1.y)-(c8.x,c8.y),4
line (c2.x,c2.y)-(c5.x,c5.y),4
line (c3.x,c3.y)-(c7.x,c7.y),4
line (c4.x,c4.y)-(c6.x,c6.y),4

'waits for keypress to quit
sleep

well there it is!! now, will somebody please show me a way to rotate it!?

8) Smile Big Grin :bounce: :rotfl: :o :barf: :oops:
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#2
Smile Cool cube,. You got more patience to set up all the lines than I do.. :wink:

Rotate? Eh heh, hmm, thats a bit more to that.. Need to look at some of Rel's 3D tuts.. :wink:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#3
hey thnx, setting up the lines is the fun part! :bounce: i think i have to use sin and cos to get it to rotate... i'm learning about it now
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#4
well, nobody would help me rotate my cube Sad

guess i had to do it myself Big Grin

Code:
dim x as integer
dim y as integer
dim xmov as integer
dim ymov as integer
dim xval as integer
dim yval as integer
dim angle as double
'screen mode
screen 13

'type, its kinda like sayin integer, its our own kindof type
type cubecorner
   x as integer
   y as integer
end type

'c1 - c8 is a type of cube corner
dim as cubecorner c1,c2,c3,c4,c5,c6,c7,c8

x = 25
y = 25

do
   angle = angle + .01
   xmov = x * sin(angle) + y * cos(angle)
   ymov = x * sin(angle) - y * cos(angle)


'coordinates for cube corners
c1.x = 160 + xmov
c1.y = 50 + ymov
c2.x = c1.x + 30
c2.y = c1.y
c3.x = c1.x
c3.y = c1.y + 30
c4.x = c2.x  
c4.y = c3.y
c5.x = 175 - xmov
c5.y = 65 - ymov
c6.x = c5.x
c6.y = c5.y + 30
c7.x = c5.x - 30
c7.y = c6.y
c8.x = c7.x
c8.y = c5.y

'horizontal lines for cube (x)
line (c1.x,c1.y)-(c2.x,c2.y),4
line (c3.x,c3.y)-(c4.x,c4.y),4
line (c6.x,c6.y)-(c7.x,c7.y),4
line (c5.x,c5.y)-(c8.x,c8.y),4

'verticle lines for cube (y)
line (c1.x,c1.y)-(c3.x,c3.y),4
line (c2.x,c2.y)-(c4.x,c4.y),4
line (c5.x,c5.y)-(c6.x,c6.y),4
line (c8.x,c8.y)-(c7.x,c7.y),4

'slanted lines (z)
line (c1.x,c1.y)-(c8.x,c8.y),4
line (c2.x,c2.y)-(c5.x,c5.y),4
line (c3.x,c3.y)-(c7.x,c7.y),4
line (c4.x,c4.y)-(c6.x,c6.y),4

'waits for keypress to quit
sleep 10
cls
loop

yay :bounce:
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#5
:o How ever you managed that is something else.. What does FB support Radians and Degrees or something?? Briliant coding BTW, so compact! :o
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#6
i used sin and cos to get the rotations, heh, i'm a n00b, so its good to get a compliment, its really encouraging
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#7
Try putting your coordinate types into an array instead of using c1,c2,c3..... so you can use a loop to rotate all the vertices and include a z component in the coordinates also.
Simple perspective can be done by dividing the x and y values by z then multiplying by the width of the screen, any points behind the screen ( with a -ve z value) will cause the perspective to mess up so don't draw that stuff.
Reply
#8
Smile Heh, I was looking at the formula wrong, thought you had:

Code:
x = r * cos(ang)
y = r * sin(ang)

You have to convert to Radians on those,... How I read that I don't know, but still its a compact code... Big Grin .. blinded by amazment maybe, heh..
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)