# Why is my rotation not working

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

## Recommended Posts

I'm trying to rotate a shape around the X axis, but basically instead of rotating, it starts going in circles around the X-axis, steadily becoming more stretched out and unrecognizable until eventually it returns to it's original shape if I rotate it by 1 degree enough times. The code I use to change coordinates based on the rotation(a method in my vertex class):
	public void rotateAboutXAxis( int angle )
{
int xAxis = 0;
int yAxis = 1;
int zAxis = 2;

double tempXCoordinate;
double tempYCoordinate;
double tempZCoordinate;

tempXCoordinate = coordinates[xAxis];
tempYCoordinate = coordinates[yAxis];
tempZCoordinate = coordinates[zAxis];

angleInRadians = angle * ( Math.PI / 180 );

coordinates[ yAxis ] = (tempYCoordinate * Math.cos( angleInRadians )) + (tempZCoordinate * Math.sin( angleInRadians));
coordinates[ zAxis ] = (tempYCoordinate * (-( Math.sin( angleInRadians )))) + (tempZCoordinate * Math.cos( angleInRadians));

}


The code I use to project the coordinates( also a method in my vertex class):
	public void setProjectionCoordinates ( double [] viewingPointCoordinates )
{

int xAxis = 0;
int yAxis = 1;
int zAxis = 2;

double zPlaneNumber = 1;

double xViewer = viewingPointCoordinates[xAxis];
double yViewer = viewingPointCoordinates[yAxis];
double zViewer = viewingPointCoordinates[zAxis];

double xPoint = coordinates[xAxis];
double yPoint = coordinates[yAxis];
double zPoint = coordinates[zAxis];

int projectedDimensions = 2;
projectedCoordinates = new double [projectedDimensions];

double c;

c = (zPlaneNumber - zViewer) / (zPoint - zViewer);

projectedCoordinates[xAxis] =  (xViewer + c * (xPoint - xViewer));
projectedCoordinates[yAxis] =  (yViewer + c * (yPoint - yViewer));

projectionExists = true;
}//setProjectionCoordinates


Does anyone know why this might happen? The object traces ok initially, but slowly gets more and more stretched out before eventually turning back to normal. It sort of turns into meteor circling around the X axis.

##### Share on other sites
Quote:
 coordinates[ yAxis ] = (tempYCoordinate * Math.cos( angleInRadians )) + (tempZCoordinate * Math.sin( angleInRadians));coordinates[ zAxis ] = (tempYCoordinate * (-( Math.sin( angleInRadians )))) + (tempZCoordinate * Math.cos( angleInRadians));

This is just a drive-by shooting, but -
The usual conversion would be:
y' = y*cos - z*sin
z' = y*sin + z*cos

(with maybe angle = -angle, depending on right-hand vs left-hand coordinate system)

##### Share on other sites
Thank you. After a few changes, the rotation seems to be working with simpler 3D shapes, but not the more complicated ones. I think I have a problem with calculating which direction a polygon is facing for lighting and deciding whether or not to draw it or not.

##### Share on other sites
Are you using models created in a 3d modeling program?
If you are, then be sure to "freeze" or "reset" the ( parts of the )models translation, scaling, rotation before exporting them.

I'm struggling with finding a good explanation for what I'm trying to say...but you might just be able to know what I mean if you have a little bit of experience with modeling.

Anyway, if you don't reset those attributes, then rotations will distort the models, flattening them, stretching them, etc.

##### Share on other sites

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