need help

Started by
1 comment, last by DarkThrone 18 years, 11 months ago
I created a simple library to build 3d objects using the following struct to handle coordinates struct Point{ double x; double y; double z; } and a new struct to hold all shapes struct Shape { struct Point startpoint; struct Point angle; struct Point **holdpoints; unsigned int numberofslices; unsigned int numberofstacks; } so I can use some methods to detect colision, etc... I created a method to update values of **holdpoints to translate it, but I can't create a rotate method, please help me if you need, the help will be apreciatted.
Advertisement
Rotation is usually done with rotation matrices or with quaternions.
For 3d rotation you will need 3x3 matrix. More info about rotation matrices is here.
To rotate given vertex simly transform (multiply) it with your matrix. To rotate whole object just transfrom all points.

If you want to do rotation and translation in one matrix, you will need 4x4 matrix. You can find much more about matrices and quaternions in Matrix and Quaternion FAQ.
Thanks for the help on references, but if any can, I like some piece of code to help me understand all theory ( It's too much to read and understand further no examples, and the scholar in Brazil is not a "Kind of perfection", hehe...)

The Translate Method for the Library it's as follows:

(Pseudo coding)

void Translate(Shape *sh,double x,double y,double z)
{
sh->startposition = { x,y,z }
for(a=0; a <= sh->numberofstacks; a++)
{
for(b=0;b <= sh->numberofslices; b++)
{
sh->holdpoints[a] = {holdpoints[a].x + x,...}
}
}
}

if any can give me just a little code to create a rotate method only to figure what happens, will be a big help to me.

This the only piece to continue the library, all other functions are ready and well.

note: help if anyone can learn me how to apply the 3x3 matrix in a cube of 27x14x9 coordinates, for example.

This topic is closed to new replies.

Advertisement