I have a game that runs in 3D perspective view and the camera pans to keep a character on the center of the screen. After a while, I've noticed that other objects begin to "lean" or horizontally skew the farther they are from the center of the camera view, which creates quite an undesirable effect when working with sprites or certain objects in a 3D perspective view. My objective is to have specific objects, namely sprites, to stand staight up no matter their position on screen. I've developed a small visual to help explain the issue I'm having:
Example
I've tried rotating along the z axis' by varying amounts based on camera position; it somewhat fixes the problem, but the sprites then begin to skew vertically.
I've tried turning off Perspective, it works, but other objects that I wish to have perspective (Walls, floor textures) will no longer work or rotate with the camera.
Is there a way to fix or correct the skewing in a perspective angled view? Or will I have to live with it or find a different way of displaying the game?
Perspective Skewing
Started by king_koder, Aug 08 2012 07:33 PM
3 replies to this topic
#1
Posted 08 August 2012 - 07:33 PM
#2
Posted 08 August 2012 - 07:44 PM
I currently can only thing of one way to do this and that is to get the 2d pos on screen of a 3d point in space then draw the sprite at that point
look at this topic the example uses what im talking about
http://gmc.yoyogames...howtopic=416555
look at this topic the example uses what im talking about
http://gmc.yoyogames...howtopic=416555
#3
Posted 17 August 2012 - 08:44 PM
My suggestion is to set up the projection camera horizontally in all cases, and deal with looking upward and downward by way of a shear transform. This can be done as follows, if I am not mistaken (not tested my code).
d3d_set_projection (0,0,0, 1,0,0, 0,0,1);
d3d_transform_set_translation (-camx,-camy,-camz);
d3d_transform_add_rotation_z (-point_direction (camx,camy, charx,chary));
d3d_transform_add_skew_x (0, -(charz-camz)/point_distance (camx,camy, charx,chary));
See my signature for d3d_transform_add_skew_x.
d3d_set_projection (0,0,0, 1,0,0, 0,0,1);
d3d_transform_set_translation (-camx,-camy,-camz);
d3d_transform_add_rotation_z (-point_direction (camx,camy, charx,chary));
d3d_transform_add_skew_x (0, -(charz-camz)/point_distance (camx,camy, charx,chary));
See my signature for d3d_transform_add_skew_x.
#4
Posted 21 August 2012 - 01:21 AM
If the above get's too complicated, you can also solve this with rotations to draw the sprites always facing the camera.
d3d_transform_add_rotation_x(90 + point_direction(0, 0, point_distance(x, y, camx camy), z - camz)) d3d_transform_add_rotation_z(point_direction(camx, camy, x, y) - 90) d3d_transform_add_translation(x, y, z) draw_sprite(sprite, image_index, 0, 0) d3d_set_identity()
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











