It looks like you're new here. If you want to get involved, click one of these buttons!

- 141K All Categories
- 103.8K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 551 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.9K Visual Basic
- 2.6K Game programming
- 317 Console programming
- 92 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 744 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 258 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 604 Jobs Wanted
- 210 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 355 Comments on this site
- 70 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 629 Off topic board
- 217 Mobile & Wireless
- 89 Android
- 126 Palm Pilot
- 340 Multimedia
- 156 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 942 Software Development
- 417 Algorithms
- 68 Object Orientation
- 92 Project Management
- 95 Quality & Testing
- 269 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 62 AJAX
- 5 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 308 WEB Servers
- 151 WEB-Services / SOAP

Shkaboinka
Member Posts: **79**

in 3D Graphics

How do you keep track of how something is rotated? I know hod to do rotation along 6 basic axis, but what I want to do is have a constant (static, doesnt change) position and re-calculate the angle every at re-draw. This keeps a figure from getting warped, AND makes it so you can rotate on a plane that has been rotated.

I noticed that the TI89 uses something called "eyes" to keep track of where the camera is around the figure and at what angle.

Can anybody tell me how to do this or any other strategy that will work? otherwise I will have to keep a list of every preiouvs rotation, which will slow things down more and more as it goes along

I noticed that the TI89 uses something called "eyes" to keep track of where the camera is around the figure and at what angle.

Can anybody tell me how to do this or any other strategy that will work? otherwise I will have to keep a list of every preiouvs rotation, which will slow things down more and more as it goes along

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2017 Programmersheaven.com - All rights reserved.

## Comments

1,035✭:

: I noticed that the TI89 uses something called "eyes" to keep track of where the camera is around the figure and at what angle.

:

: Can anybody tell me how to do this or any other strategy that will work? otherwise I will have to keep a list of every preiouvs rotation, which will slow things down more and more as it goes along

:

Don't know what to tell you on the 89. I use GL and each object structure has three axis vars for storing the rotation values. Dunno' what your extra three axis are, unless you mean time, space, and something. Maybe you could explain what the fourth, fifth, and sixth dimensions are so we can better understand and help you?

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

349:

I use the same method in DirectX: I have an object class and a Rotation 3D vector inside it, whose component are the current object angle.

You can easily calculate the rotation matrix having the three angles simply multiplying the rotation matrices on each of the 3 axis.

nICO

[hr]

[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]

JOHN KEATS

79:

: -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

:

Well on the TI83+, you have tto save mem / speed; it takes more to store +angle and -angle sin&cos values, so I just use a +angle; to rotate backwards though, you just switch the axis. Thus, I tell it to rotate along XY, XZ, YZ, YX, ZX, or ZY axis.

What do you mean by storing angle values? I think I know, but then you must know which comes first. EX: rotating 5* on XY and then 5* on ZX is NOT the same as doing ZX and then XY rotation, so how does it compensate? Is one referenced from the other like one of those multi-axis spinny things that you get in the middle of and it spins on many axis at once?

79:

: nICO

:

: [hr]

: [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]

: JOHN KEATS

:

Can you say that in English? how you multiply what matrix on the axis? Just so you know, I am doing this all MANUALLY (I learned how to program in Java and do window components & Graphics; I figured out all the stuff I use for 3D stuff, I just tell Java to draw the 2D version of it all)

349: Can you say that in English?

how you multiply what matrix on the axis? Just so you know, I am doing this all MANUALLY (I learned how to program in Java and do window components & Graphics; I figured out all the stuff I use for 3D stuff, I just tell Java to draw the 2D version of it all)

:

It's not difficult...

A 3D world can be defined by 3 axis, x, y and z.

So, the rotation of the object can easily be stored with 3 params, that you can call rotx, roty and rotz and represent the rotation around the above axis.

You can represent every transformation in the 3D space with a matrix that you can use to multiply the coordinates of a 3D point to get its transformed.

That means that:

[code]

- -

| M11 M12 M13 |

[x' y' z'] = [x y z] * | M21 M22 M23 |

| M31 M32 M33 |

- -

[/code]

The rotation matrices are:

[code]

X rotation:

- -

| cos(rotx) -sin(rotx) 0 |

| sin(rotx) cos(rotx) 0 |

| 0 0 1 |

- -

Y rotation:

- -

| 1 0 0 |

| 0 cos(roty) -sin(roty) |

| 0 sin(roty) cos(roty) |

- -

Z rotation:

- -

| cos(rotz) 0 sin(rotz) |

| 0 1 0 |

| -sin(rotz) 0 cos(rotz) |

- -

[/code]

So, if your object is rotated 20 degrees on x 30 on y and 50 on z you just calculate the sin and cos of the 3 angles, substitute them in the matrices, then do Mx * My * Mz (multiply the 3 matrices) and, at last, multiply your point 3D coords by the matrix you obtained.

And that's all...

PS: this is the best way I can express myself in English... if you don't understand I can always explain it to you in Italian!

nICO

[hr]

[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]

JOHN KEATS

79: A 3D world can be defined by 3 axis, x, y and z.

: So, the rotation of the object can easily be stored with 3 params, that you can call rotx, roty and rotz and represent the rotation around the above axis.

: You can represent every transformation in the 3D space with a matrix that you can use to multiply the coordinates of a 3D point to get its transformed.

:

: That means that:

:

: [code]

: - -

: | M11 M12 M13 |

: [x' y' z'] = [x y z] * | M21 M22 M23 |

: | M31 M32 M33 |

: - -

: [/code]

:

: The rotation matrices are:

:

: [code]

: X rotation:

:

: - -

: | cos(rotx) -sin(rotx) 0 |

: | sin(rotx) cos(rotx) 0 |

: | 0 0 1 |

: - -

:

: Y rotation:

:

: - -

: | 1 0 0 |

: | 0 cos(roty) -sin(roty) |

: | 0 sin(roty) cos(roty) |

: - -

:

: Z rotation:

:

: - -

: | cos(rotz) 0 sin(rotz) |

: | 0 1 0 |

: | -sin(rotz) 0 cos(rotz) |

: - -

:

: [/code]

:

: So, if your object is rotated 20 degrees on x 30 on y and 50 on z you just calculate the sin and cos of the 3 angles, substitute them in the matrices, then do Mx * My * Mz (multiply the 3 matrices) and, at last, multiply your point 3D coords by the matrix you obtained.

:

: And that's all...

:

: PS: this is the best way I can express myself in English... if you don't understand I can always explain it to you in Italian!

:

: nICO

:

: [hr]

: [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]

: JOHN KEATS

:

I am still a little confused... is there ONE matrix that you multiply [x,y,z] by? I guess each is found by it's corresponding rotation matrix, but how? you can't multiply [x] by a 3x3 Matrix; do I find the determinant of each to find the new coordinates?

349Multiplying a 1*3 vector by a 3*3 matrix yealds to a 1*3 vector

[x' y' z'] that contains the transformed point coords.

nICO

[hr]

[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]

JOHN KEATS

79how do you keep the 3 angles updated? This better not be about simple rotation, which I can do; This IS about keeping track of 3 constantly changing transformation angles and finding each orientation from a constant postition, right?

I don't see anything in there that explains how to keep track of this stuff, just some compicated steps for ONE rotation. Can you explain, or do you really know what I'm talking about?

(thanks for your help)

79lets say that you have 3 numbers to keep track of x,y, and z rotation.

They start out at zero: rotate 30 degrees around the x-axis, and the xnumber is 30, but the y and z numbers are affected; then rotate around the y-axis 45 degrees: ynumber=45, and the other angles are affected... do this many times...

now the figure has never really moved; to get it to the postion where it should be after all that, find where the angles meet or something...but then it may be rotated incorrectly around the axis described by these combined rotations (not sure); wouldn't that work?

How would you rotate on WHICH plane(s) to get it in that orientation? I suppose any might work, as long as you re-figure it for every point...what can you say of any of this; is that what the whole matrices thing does?

349I have a class CObj that contains 3 members: Pos, Rot and Scale, that are 3D vector, so that each of this member store 3 values, 1 for each axis.

I also have a CApp class that contains a list of CObj objects, and also other stuff (like cameras, lights, textures and so on).

The CObj class has various methods to set the position, the rotation and the scaling of the objects... so every time I change a value I recalculate the position, rotation and scaling matrices (position and scaling can be handled easily with matrices, like I told you for rotation). Note that I recalculate the matrices only when needed.

I also store the pos*scale*rot matrix, so I don't have to calculate it for every frame; note that the multiplication of matrices is NOT commutative (ie. A*B is different from B*A) so the order matters and it's important to multiply the matrices in the correct order or you'll have wrong results.

You should also calculate a perspective matrix, that corrects the trasformation obtained by the above matrix, taking in account the perspective (this matrix depends by the camera parameters).

So... it's a lot of math stuff and it's not as easy as it seems!

If you want to do something estetically good and in real-time I suggest you to use DirectX or OpenGL (the one which you prefer, they're both good) and to switch to C++.

nICO

[hr]

[italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]

JOHN KEATS