Page 1 of 1

Qbasic4.5 Codes 03: A useful 3D rotation function.

Posted: Thu Apr 13, 2006 11:19 am
by NeonAmd64
Complex Complex and complex.... Nothing is easy in my life but I will try to make it easy for you as much as I can...

This is a code to rotate a point the in a 3D world which can be useful for 3D games:

Description: The function will rotate a point in its axes.

Caution:
The code will acquire the cosine table sub routine to rotate the point of course in little height speed. [You can refere to Qbasic4.5 Codes 01 high speed Cosine and Sine] under Game Creation board of this forum.

Here is the code:

This will make the arrays and the variables that are required:

Code: Select all

DIM SHARED cose!(360), sine!(360)
DIM SHARED Xrotate!, Yrotate!, Zrotate!
This is a cos table sub routine:

Code: Select all

DEFSNG A-Z
SUB cosine.table
RA = (180 / (22 / 7))
FOR i = 0 TO 360
cose!(i) = COS(i / RA)
sine!(i) = SIN(i / RA)
NEXT i
END SUB
This is the function that you need to rotate a 3D point the scene:

Code: Select all

SUB D3d.rotate (xpROT!, ypROT!, zproT!, xROT%, yROT%, zroT%)
xROT% = xROT% - &#40;INT&#40;xROT% / 360&#41; * 360&#41;&#58; IF xROT% < 0 THEN xROT% = xROT% + 360
yROT% = yROT% - &#40;INT&#40;yROT% / 360&#41; * 360&#41;&#58; IF yROT% < 0 THEN yROT% = yROT% + 360
zroT% = zroT% - &#40;INT&#40;zroT% / 360&#41; * 360&#41;&#58; IF zroT% < 0 THEN zroT% = zroT% + 360
X.X! = xpROT!
Y.X! = &#40;cose!&#40;xROT%&#41; * ypROT!&#41; - &#40;sine!&#40;xROT%&#41; * zproT!&#41;
Z.X! = &#40;sine!&#40;xROT%&#41; * ypROT!&#41; + &#40;cose!&#40;xROT%&#41; * zproT!&#41;
X.Y! = &#40;cose!&#40;yROT%&#41; * X.X!&#41; + &#40;sine!&#40;yROT%&#41; * Z.X!&#41;
Y.Y! = Y.X!
Z.Y! = &#40;cose!&#40;yROT%&#41; * Z.X!&#41; - &#40;sine!&#40;yROT%&#41; * X.X!&#41;
xrotate! = &#40;cose!&#40;zroT%&#41; * X.Y!&#41; - &#40;sine!&#40;zroT%&#41; * Y.Y!&#41;
Yrotate! = &#40;sine!&#40;zroT%&#41; * X.Y!&#41; + &#40;cose!&#40;zroT%&#41; * Y.Y!&#41;
Zrotate! = Z.Y!
END SUB
Done&#8230; :)

I think a program in basic can be converted to any other language. useful heh.. :laugh:
So If explanation is needed then ask me.. I know you wouldn&#8217;t because you are clever .. :)

I had created lots of codes during my life and I am happy to share it with you&#8230;. If anyone is interested then take it ... and send me at least Personal message..

Are you interested in what I have then goto
http://neonamd64.atspace.com/

Posted: Thu Apr 13, 2006 12:15 pm
by dosraider
RAR wrote: ! D:\temp\testingQB\d2dshootinggame.part01.rar: Unexpected end of archive
! D:\temp\testingQB\d2dshootinggame.part02.rar: Unexpected end of archive
! D:\temp\testingQB\d2dshootinggame.part03.rar: Unexpected end of archive
! D:\temp\testingQB\d2dshootinggame.part04.rar: Unexpected end of archive
! D:\temp\testingQB\d2dshootinggame.part05.rar: Unexpected end of archive
:o

Posted: Thu Apr 13, 2006 7:59 pm
by Dosser
Looks interesting:
-what do x.x, y.y, x.y etc represent?
-Have you tested it yet? Put it on a cube model or something and see what happens.
-Also, is it a problem that you can only do integer rotations? A large object might look a little 'clunky' as it rotates.
-rotation is probably the hardest function to do, but have you got others as well? Transposition (moving an object left, right, up, down as if they are strafing), and scaling (shrinking / expanding as if the player is moving towards / away from it) are also important 3D functions.

Web Host files error not mine

Posted: Fri Apr 14, 2006 8:54 am
by NeonAmd64
dosraider

My apology for this error but this is not my mistake, it is the web host mistake. It tries to embed its ads in the html file…. B)

Never mind, now I updated the files. :) You can start downloading:
http://neonamd64.atspace.com/game.html

My apology for the delay... :shame:
and thank you for the last advice :)

Remember : you have to see the sentence “replace the extension ".jpg" with ".rar"

Dosser

Posted: Fri Apr 14, 2006 9:22 am
by NeonAmd64
Now, I can see .... hmmm.... Ok :)

Dosser
what do x.x, y.y, x.y etc represent?
Here is an explanation in brief,
ROT : is a function input. It is standing for "rotation";.
So xROT% is the rotation around the x axes ...etc
pROT: is a function input. It is standing for "Point position for rotation".
So xpROT% is the x position of the point referenced to world position...etc

X.X!, Y.X!, Z.X!, X.Y!,Y.Y! and Z.Y! all are temporary variables .. it is usefull instead of this:
Result% = (XP*(YP+((Xani/100)*1000))+cos(sin(tan(123454)*ang1)*ange3+pos1&.......I give up. :Angry:

xrotate!, yrotate!, zrotate! I call them general variables; they are used to get the resultant position of the point.
Have you tested it yet? Put it on a cube model or something and see what happens.
Like to see it in such an application then download my final 3D object Editor package..
-Also, is it a problem that you can only do integer rotations? A large object might look a little 'clunky' as it rotates
You are right on the line but understanding the variable purpose and how the function works then you will be in safe side. :)

Remember, angles use an integer value, which is enough, but the position should be in real value.
-rotation is probably the hardest function to do, but have you got others as well? Transposition (moving an object left, right, up, down as if they are strafing), and scaling (shrinking / expanding as if the player is moving towards / away from it) are also important 3D functions.
Try my 3D Editor Package and you will see what I have;

And sooner or later I will give my effort to provide you with what you need to create the 3D world .. all in Qbasic..
don't worry... :)

Interested in basic game programming then I will support you... :)

Direct link:
http://neonamd64.atspace.com/qbas.html
Doesn't work then goto:
http://www.freewebs.com/neonamd64/qbas.html