Sign in to follow this  
DarkZoulz

mesh is flattend when rotating

Recommended Posts

Hi, my 3D data is kind of flattend when I attempt to rotate it. This is my rotation routine:
void Vertex::Rotate(Vertex &result, const float roll, const float pitch, const float yaw) const
{
	const float x1 = x * cos(roll) - y * sin(roll);
	const float y1 = x * sin(roll) + y * cos(roll);

	const float z1 = x1 * sin(yaw) + z * cos(yaw);
	result.x = x1 * cos(yaw) - z * sin(yaw);

	result.z = z1 * cos(pitch) - y1 * sin(pitch);
	result.y = z1 * sin(pitch) + y1 * cos(pitch);
}
btw, I have to do it without matrices. It's an assignment.

Share this post


Link to post
Share on other sites
The code looks correct to me.
Maybe the flattening has some other reason.
Did you check the aspect ratio?

Share this post


Link to post
Share on other sites
Do you mean the distance between the "eye and the screen" that I use in my projection calculations or? If so, it is set to screen width / 2.

This is my projection calculation (vertex -> 2D point).

void Vertex::Project(Point<int> &result, const float d) const
{
result.x = d * (x / z);
result.y = d * (y / z);
}

Share this post


Link to post
Share on other sites
???
- Are you using a software renderer ?
- Why are you projecting the vertices yourself ?
It's normally the job of the 3D API, (GL or D3D).

- Anyway having discretized int results is really not the way to do. This could cause your problem.

- Are you applying subsequent rotations on the same vertices ( like this : V.Rotate(V) ) several times ?

The way to do is accumulate Euler angles (or matrices)from frame to frame and keep the original vertices unchanged. It's the most probable reason for the flattening, because numerical errors accumulate, and a unitary cube can become as flat as a paper sheet.

Share this post


Link to post
Share on other sites
I have a original copy of the mesh in memory. I apply the rotation and translation to a copy. Then render it and discard it. Repeat.

Maybe it's because of my datatype choices? what datatypes should I use? a 2D point does not need to be a float, or?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this