# mesh is flattend when rotating

This topic is 5263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
The code looks correct to me.
Maybe the flattening has some other reason.
Did you check the aspect ratio?

##### 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 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 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?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634111
• Total Posts
3015573
×