#### Archived

This topic is now archived and is closed to further replies.

# Problem rotating sprite in 3D.

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

## Recommended Posts

Hi, im trying to rotate a 2D sprite image anlong the Z axis, to simulate a plane banking. Its actually working fine, except when i try and bank right, instead of left. The main class is PixMap which loads the image data in a int[width][height][colors]. It contains a projectImage() with center of projection, front plane distance, and the rotation values. The destination PixMap pixel at the projected x,y equals the pixel of the source PixMap before rotation and projection. So when i call the project() with 0.3 roll, it banks fine to the left, but when i pass -0.3 there is a weird streching, with blank vertical lines. This is my first attempt at 3D projections so im not supprised its a bit wrong, but its close. Here is the projectImage(). note this is java with out java3D. Thanks for any ideas! Harley.


public Image projectImage(float dx,float dy,float dz,float zp,   float yaw,float pitch,float roll, Component comp)
{
PixMap dstMap =new PixMap(width * 4, height * 4, 4);

float dxz = dx/dz;
float dyz = dy/dz;

for(int i=0; i<width; i++)
{
for(int j=0; j<height; j++)
{
double x = i;
double y = j;
double z = 1;

// rotate x axis

x = z * Math.sin(yaw) + x * Math.cos(yaw);
z = z * Math.cos(yaw) - x * Math.sin(yaw);
// rotate y axis

y = (y * Math.cos(pitch)  - z * Math.sin(pitch));
z = (y * Math.sin(pitch) + z * Math.cos(pitch));
// rotate z axis

x = (y * Math.sin(roll) + x * Math.cos(roll));
y = (y * Math.cos(roll) - x * Math.sin(roll));

double xp = (x - (z * dxz)  +  (zp * dxz)) / (( zp - z) / dz + 1);
double yp = (y - (z * dyz)  +  (zp * dyz)) / (( zp - z) / dz + 1);
dstMap.setPixel(pixMap[i][j],(int)xp, (int)yp);

}
}

return dstMap.createImage(comp);
}



1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631418
• Total Posts
2999972
×