Rotating a 3d cube in software rendering
What do i need to know to rotate a 3d cube in software rendering? I dont mind picking up book''s on math, but i don''t want to pick up a 3d game programming book for this, or anything that shows me directly how to do it. I want to think up my own algorithm for this, not be spoon fed. I dont consider using any math text books for help though as being spoon fed, math is math, it never changes, and its the basis behind 3d graphics. Anyway, if anyone here did this at one point without looking at someone else''s code, what did you know? Was the math you learned from high school enough, or did you need to do a little extensive research?
This is very simple, if you know the jargon. All you do is create a rotation matrix (there are several tutorials on doing this floating around.) Then you store your object's vertices as vectors.
Then you multiply each vector by the rotation matrix. This will give you the rotated vertexes that you need to draw.
You really need to understand vectors and matrix math to 'get' this. I learned matrices and vectors in high school, but I know that not all state/town school systems teach this.
Try the tutorials about matrices here http://www.gamedev.net/reference/list.asp?categoryid=28
If you want to get a book on doing this, I recommend 'elementary linear algebra,' but you'll probably only need the first 20-30% of the book for this applciation.
Edited by - cheesegrater on March 11, 2002 11:33:43 AM
Then you multiply each vector by the rotation matrix. This will give you the rotated vertexes that you need to draw.
You really need to understand vectors and matrix math to 'get' this. I learned matrices and vectors in high school, but I know that not all state/town school systems teach this.
Try the tutorials about matrices here http://www.gamedev.net/reference/list.asp?categoryid=28
If you want to get a book on doing this, I recommend 'elementary linear algebra,' but you'll probably only need the first 20-30% of the book for this applciation.
Edited by - cheesegrater on March 11, 2002 11:33:43 AM
March 11, 2002 10:57 AM
Hi,
To rotate a cube, you have to know how to rotate a point.
Consider reading tutorials about transformation matrices,
and vectors.
You''ll find all you need to rotate a point.
I don''t have any website to give you, but you said you
don''t want to be "spoon fed", so i let you search![](smile.gif)
high school maths are enough to find it on your own.
You don''t really need to know about matrices, but
matrices and vectors are so ... smoofey
(i don''t know if this word exists but, i think
it is the most accurate![](smile.gif)
(please excuse me for my english because i''m french)
(excuse me for my (poor) humour too)
To rotate a cube, you have to know how to rotate a point.
Consider reading tutorials about transformation matrices,
and vectors.
You''ll find all you need to rotate a point.
I don''t have any website to give you, but you said you
don''t want to be "spoon fed", so i let you search
![](smile.gif)
high school maths are enough to find it on your own.
You don''t really need to know about matrices, but
matrices and vectors are so ... smoofey
(i don''t know if this word exists but, i think
it is the most accurate
![](smile.gif)
(please excuse me for my english because i''m french)
(excuse me for my (poor) humour too)
I never paid attention in high school math class so it took me a while to figure it out. The trick is to realize that many functions can be represented as a matrix. Column i of the matrix is the function f applied to the ith standard basis vector. So f((1,0,0)) would give you some other vector, say (cos theta, sin theta, 0), which would be the first column in your matrix. With this, you can derive the rotation and scaling matrices. When you multiply this matrix M by a point p M*p, you get the transformed point. Translations are a bit tricky because any ordinary 3d linear function will not translate a point (simply because it is required to map the 0 vector to itself). The way around this is to use a 4d transformation and set all vector at (x,y,z,w), and making sure w never equals 0. These are the basics you need for a cube. Since straight lines are preserved in affine transformations, you can just transform each vertex of the cube by multiplying it by the rotation matrix, then drawing a line to connect the dots after the rotation. Of course this is just for a wireframe reprentation without perspective. Shading and perspective are interesting subjects but too long to discuss here.
Matrices are just one way of doing it - thought admittedly the most robust, flexible, and common one! It may make more sense to treat rotation as something a little less abstract and easier to wrap your head around - that''s often important when you''re re-inventing the wheel (I do it often!). With that said, another place to begin your research is with converting rectangular coordinates to polar coordinates and back again. In polar coordinates, rotation is trivial addition!
Ok, I pretty much know what i need to rotate it. But what about to draw it? I think this is pretty hard, but im probably wrong. I can draw a 2D cube. Is 3D as simple as adding a z-axis?
March 13, 2002 11:17 AM
quote:
Original post by CannoN346
Ok, I pretty much know what i need to rotate it. But what about to draw it? I think this is pretty hard, but im probably wrong. I can draw a 2D cube. Is 3D as simple as adding a z-axis?
It''s actually pretty complicated. You''re going to need to learn about world to screen transformation, perspective transformation, scanfill algorithms, and lighting models (if you want shading). Certainly more detailed that I can get in a forum post.
If you''ve got the cash, I''d recommend that you purchase a book on computer graphics theory. (If you have a college nearby, or are a college student, check the campus bookstore around the time the next semester starts.)
If you don''t have the cash, I''d go with hardware rendering in OpenGL or DirectX for now. It''s more covered by free sources and tutorials.
Well, one easy way to do it without perspective is to simply drop the z coordinate. If you want perspective, a relatively simple way to do it is to divide your x and y components by your z component (thus making it smaller as you go further back). You can of course scale this up and down to your liking. To shade it, you need to know two things. You need to calculate the normal vector of each face of the cube. This is simple for a cube, because it sticks straight out in the direction of x,y,z,-x,-y and -z for each of the 6 faces. Then for each rotation, rotate the normals too. You also need to know the direction vector from center of each face to the light source. Then by normalizing both vectors and dotting them to each other, you can have a scalar from 0.0 to 1.0 which will tell you what fraction of an original intensity you should have. If you don''t want to shade it yet, a simple way to go about this is to make each face a different color.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement