|
Pages: [1]
|
 |
|
Author
|
Topic: cool 3d thing (edit: now available in screensaver form!) (Read 1840 times)
|
Deleter
Na_th_an
    
Posts: 1292

|
its not too complicated, so dont get your hopes too high, but i like it. DECLARE SUB rotpt (x1!, y1!, z1!, rotx!, roty!, rotz!, nx!, ny!, nz!) DECLARE FUNCTION dstc(x1!,y1!,x2!,y2!,d!) AS BYTE CONST pi = 3.14159 / 180 DIM AS SINGLE x,y,z,thetax,thetay,thetaz, c,ox,oy,bx,by,bz,cx,cy,tm DIM AS INTEGER sc(639*479+1),mousex,mousey,garbage RANDOMIZE TIMER SCREENRES 640,480,32,2 SCREENSET 1,0 ox = 320 oy = 240 cx = -5 cy = -8 tm = TIMER + .03 DO FOR thetax = 0 TO 180 STEP 36 FOR thetay = 0 TO 360 STEP 6 rotpt (0,0,125,thetay,thetax+90+thetaz,thetaz+90,x,z,y) c = (y+128) SHL 16 LINE (ox-x-1,oy-z-1)-(ox-x+1,oy-z+1),c, bf rotpt (0,0,225,-thetay,-thetax+90-thetaz,-thetaz+90,bx,bz,by) c = ((y*.55)+128) LINE (319-bx,239-bz)-(321-bx,241-bz),c, bf NEXT NEXT SCREENCOPY 1,0 GET (0,0)-(638,478),sc CLS DO:LOOP UNTIL TIMER >= tm tm = TIMER + .03 PUT(1,1),sc,alpha,225 LINE(0,0)-(639,0),0 LINE(0,0)-(0,479),0 thetaz +=2 ox += cx IF ox < 125 OR ox > 514 THEN cx = -cx oy += cy IF oy < 125 OR oy > 354 THEN cy = -cy LOOP UNTIL MULTIKEY(1) END SUB rotpt (x1!, y1!, z1!, rotx!, roty!, rotz!, nx!, ny!, nz!) DIM AS SINGLE rx,ry,rz rx = rotx! ry = roty! rz = rotz! 'xrot nx1! = x1! ny1! = z1! * SIN(pi * rx) + y1! * COS(pi * rx) nz1! = z1! * COS(pi * rx) - y1! * SIN(pi * rx) 'yrot nx2! = nx1! * COS(pi * ry) - nz1! * SIN(pi * ry) ny2! = ny1! nz2! = nx1! * SIN(pi * ry) + nz1! * COS(pi * ry) 'zrot nx! = nx2! * COS(pi * rz) - ny2! * SIN(pi * rz) ny! = nx2! * SIN(pi * rz) + ny2! * COS(pi * rz) nz! = nz2! END SUB
FUNCTION dstc(x1!,y1!,x2!,y2!,d!) AS BYTE IF SQR((x1!-x2!)*(x1!-x2!)+(y1!-y2!)*(y1!-y2!)) > d! THEN RETURN -1 ELSE RETURN 0 END FUNCTION
|
|
|
|
|
Logged
|
|
|
|
Deleter
Na_th_an
    
Posts: 1292

|
ok, following the advice of rattrap, i made it into a screensaver. Download screensaverHere is the code for those who are interested: edit: changed the code to make the empty settings thing look more windows-y, lol IF LEFT$( COMMAND$, 2 ) = "/c" THEN 'settings DIM AS INTEGER mx,my,mb, txt(340*40) SCREENRES 400,300,32,2,0 SCREENSET 1,0 WINDOWTITLE "Sphereoyds© Settings" PAINT (0,0), RGB(255,0,255) COLOR RGB(0,0,0), RGB(255,0,255) PRINT "Sorry, no settings are currently available." PRINT PRINT " Screensaver by Deleter," PRINT PRINT " 'Sphereoyds' (c) 2005" GET (0,0)-(339,39),txt CLS PAINT(0,0), RGB(212,208,200) PUT (29,129),txt,trans SCREENCOPY 1,0 SLEEP END END IF IF LEFT$( COMMAND$, 2 ) = "/p" THEN END DECLARE SUB rotpt (x1!, y1!, z1!, rotx!, roty!, rotz!, nx!, ny!, nz!) DECLARE FUNCTION keypressed() CONST pi = 3.14159 / 180 DIM AS SINGLE x,y,z,thetax,thetay,thetaz, c,ox,oy,bx,by,bz,cx,cy,tm DIM AS INTEGER sc(639*479+1),mousex,mousey,garbage RANDOMIZE TIMER SCREENRES 640,480,32,2,1 SCREENSET 1,0 SETMOUSE 320,240,0 ox = 320 oy = 240 cx = -2.5 cy = -4 tm = TIMER + .03
DO FOR thetax = 0 TO 180 STEP 36 FOR thetay = 0 TO 360 STEP 6 rotpt (0,0,125,thetay,thetax+90+thetaz,thetaz+90,x,z,y) c = (y+128) SHL 16 LINE (ox-x-1,oy-z-1)-(ox-x+1,oy-z+1),c, bf rotpt (0,0,225,-thetay,-thetax+90-thetaz,-thetaz+90,bx,bz,by) c = ((y*.55)+128) LINE (319-bx,239-bz)-(321-bx,241-bz),c, bf NEXT SLEEP 1 NEXT SCREENCOPY 1,0 GET (0,0)-(638,478),sc CLS DO:LOOP UNTIL TIMER >= tm tm = TIMER + .03 PUT(1,1),sc,alpha,225 LINE(0,0)-(639,0),0 LINE(0,0)-(0,479),0 thetaz +=2 ox += cx IF ox < 125 OR ox > 514 THEN cx = -cx oy += cy IF oy < 125 OR oy > 354 THEN cy = -cy LOOP UNTIL keypressed END SUB rotpt (x1!, y1!, z1!, rotx!, roty!, rotz!, nx!, ny!, nz!) DIM AS SINGLE rx,ry,rz rx = rotx! ry = roty! rz = rotz! 'xrot nx1! = x1! ny1! = z1! * SIN(pi * rx) + y1! * COS(pi * rx) nz1! = z1! * COS(pi * rx) - y1! * SIN(pi * rx) 'yrot nx2! = nx1! * COS(pi * ry) - nz1! * SIN(pi * ry) ny2! = ny1! nz2! = nx1! * SIN(pi * ry) + nz1! * COS(pi * ry) 'zrot nx! = nx2! * COS(pi * rz) - ny2! * SIN(pi * rz) ny! = nx2! * SIN(pi * rz) + ny2! * COS(pi * rz) nz! = nz2! END SUB
FUNCTION keypressed() DIM AS INTEGER temp,tx,ty FOR temp = 0 TO 127 IF MULTIKEY(temp) THEN RETURN -1 NEXT GETMOUSE tx,ty,,temp IF tx <> 320 OR ty <> 240 OR temp <> 0 THEN RETURN -1 RETURN 0 END FUNCTION
|
|
|
|
|
Logged
|
|
|
|
|
|
Dio
I hold this place together
    
Posts: 874

|
how was it made? i'm not kidding. oh let's start with rotptbtw, where the hell do you people learn any of this stuff? did i miss something? goddamn, where the hell is a good, thorough, tutorial to help me?! Damn. thank you that is all. oh, and that look pretty cool edit: i used the wrong word. go figure
|
|
|
|
|
Logged
|
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote] Here
|
|
|
|
|
|
|
|
|
Rattrapmax6
__/--\__
    
Posts: 2577

|
:lol: Yeah, SUB rotpt (x1!, y1!, z1!, rotx!, roty!, rotz!, nx!, ny!, nz!) DIM AS SINGLE rx,ry,rz rx = rotx! ry = roty! rz = rotz! 'xrot nx1! = x1! ny1! = z1! * SIN(pi * rx) + y1! * COS(pi * rx) nz1! = z1! * COS(pi * rx) - y1! * SIN(pi * rx) 'yrot nx2! = nx1! * COS(pi * ry) - nz1! * SIN(pi * ry) ny2! = ny1! nz2! = nx1! * SIN(pi * ry) + nz1! * COS(pi * ry) 'zrot nx! = nx2! * COS(pi * rz) - ny2! * SIN(pi * rz) ny! = nx2! * SIN(pi * rz) + ny2! * COS(pi * rz) nz! = nz2! END SUB  Read up on Relsolf's 3D tuts for QB if you want a basic understanding (pun intended) :wink: Edit: Ah, yeah, I found a replacement for my saver for awhile..  ..That just looks too cool.. :lol:
|
|
|
|
|
Logged
|
Kevin ( x.t.r.GRAPHICS) 
|
|
|
syn9
Senior Member
 
Posts: 175

|
hah! i didnt say i didnt know how it worked... i said i didnt know why all my returned X points were negative! >D
heres a tutorial i wrote on why it works... >)
for rotation on a 2d plane, take a normal x/y axis and place a point on the x axis somewhere
a simple exercise would be to rotate that point by 90 degrees up to the y axis
so point [10,0] becomes [0,10]
well, cos(0degrees) = 1 and sin(90 degrees) = 1
so if you want the x value to be at 10 on the x axis at 0 degrees then multiply the x value by cos(angle), this will give you the rotated x coordinate
now, since you want that initial point on the x axis to be put up to the top of the y axis, you'll multiply the x point times sin(90) so that at 90 degrees the rotated y value will be 10 units high
so far you have
rotatedx = x * cos(angle) rotatedy = x * sin(angle)
so that if you put in the coordinate [10,0] it will be on the x plane at value 10 at 0 degrees and it will be on the y plane at 90 degrees...
now, say you want the point [10,2] the be rotated 90 degrees, well, at 0 degrees y ou want the point to be 2 units above the x axis
so you add to your rotatedy value y * cos(0) because at 0 degrees cos(0) = 1 and sin(0) = 0... so that your x*sin[0] = 0 and y*cos[0] = 2, now your rotatedy formula will acurately rotate this point that is not exactly on the x axis
next is to fix the rotatedx formula so that at 90 degrees the original [10,2] is rotated to [-2,10] in order to do this your rotated x value needs to end up at -2 at 90 degrees, well, cos[90] = 0 so you need to use sin[90] and multiply it by the negative of the original y value
so you end up with
rotatedx = x * cos[angle] - y * sin[angle] rotatedy = x * sin[angle] + y * cos[angle]
this will allow rotation on one plane, in 3d you have 3 planes, so the outputed rotatedx/y from this formula will be applied to the next plane, and so on to have a final rotated coordinate in 3d
to rotate onthe x axis, you'll be rotating on a plane that only uses z and y values on the y axis, it'll be x and z values etc...
simplified it would look like this
rx1 = basex ry1 = basez * sin(xangle) + basey * cos(xangle) rz1 = basez * cos(xangle) - basey * sin(xangle)
rx2 = rx1 * cos(yangle) - rz1 * sin(yangle) ry2 = ry1 rz2 = rx1 * sin(yangle) + rz1 * cos(yangle)
rx3 = rx2 * cos(zangle) - ry2 * sin(zangle) ry3 = rx2 * sin(zangle) + ry2 * cos(zangle) rz3 = rz2
rxyz3 will be your final rotated coordinates
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|
DirkFist
New Member
Posts: 5
|
If you think about coordinates as a recipe for getting from one point to another, (eg. so many steps forward so many to the right) rotation makes more sense. Lets say you have a two dimensional system: F=Forward R=Right Now if we think of F and R as vectors in say X,Y F.x= 0.6: F.y= 0.8 R.x= 0.8: R.y=-0.6 Then a point in F1,R1 gets transformed to X,Y by X1 = F1*F.x + R1*R.x Y1 = F1*F.y + R1*R.y so 1,0 => 0.6, 0.8 0,1 => 0.8,-0.6 2,0 => 1.2, 1.6 1,1 => 1.4, 0.2 So where do sin and cos come in ? cos,sin form a unit vector The length of base vectors F and R determines the scaling of the result The direction of the base vectors determines the direction of the result The angle between the base vectors determines the skew of the result Example use mouse to rotate without sin,cos dim as single a,b, dim as single Fx,Fy,Rx,Ry 'base vectors dim as single f(10),r(10) 'point sequence dim as integer mx,my 'mouse coordinates screen 13 ' space shippy kindof of shape f(0)= 0 :f(1)=48:f(2)=54:f(3)=54:f(4)= 48 f(5)= 0 :f(6)=31:f(7)=26:f(8)=26:f(9)=31:f(10)=0 r(0)= 20:r(1)=16:r(2)= 6:r(3)=-6:r(4)=-16 r(5)=-20:r(6)=-16:r(7)=-6:r(8)= 6:r(9)= 16:r(10)=20 do getmouse mx,my Fx=(mx-160)/54:Fy=(my-100)/54 Rx=Fy:Ry=-Fx 'R is perpendicular to F for a=0 to 9 b=a+1 line(Fx*f(a)+Rx*r(a)+160,Fy*f(a)+Ry*r(a)+100)-(Fx*f(b)+Rx*r(b)+160,Fy*f(b)+Ry*r(b)+100) next a screensync: cls: k$=right$(inkey$,1):? "move mouse around : esc to exit" loop until k$="k" or k$=chr$(27)
|
|
|
|
|
Logged
|
|
|
|
|
Pages: [1]
|
|
|
|
|