Jump to content
  • Advertisement
Sign in to follow this  
RobMaddison

Aligning gizmo orientation with screen

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a 'gizmo' in my level editor which I use to rotate, translate and scale objects.  The gizmo is just a mesh which has 3 arrows pointing along each axis, you can hover over and click on the arrows to move, translate etc - standard stuff.  The gizmo is drawn at the same position as the object it is targeting but is a set distance away from the camera so however near or far the object is, the gizmo stays the same size.  This all works fine.

What I'm trying to do now is offer local, world and screen coordinate systems for rotating, translating, etc.  local was simple.  I basically borrow the world matrix from the targeted object (the thing we're rotating) - removing the scale.  For world, even simpler as there's no rotation at all so it's just an identity matrix set to the position of the targeted object (again set at a certain distance away from the camera).

 

Screen space is causing me lots of headaches.  My train of thought was that I would use the inverse view projection matrix of the camera which will effectively remove what will be added at the rendering stage leaving the object oriented in alignment with the screen.  This does work to a certain extent, the orientation of the gizmo stays in the right position inside the object and in an orientation aligned with the screen no matter where my camera is situated.  The problem is, the view projection matrix intrinsically contains scale (for perspective) which causes my gizmo to get smaller the further away from the object I am - even though the position of the gizmo is still that set distance away from the camera.

 

I've tried lots of different methods of removing scale but it always messes up the rendering of the gizmo.  Is there a better way or a step I'm missing?

Share this post


Link to post
Share on other sites
Advertisement

Simply create the look at matrix like that (from, to, up) or hardcode directly the matrix to avoid to transpose :

CMatrix4 LookAtMatrix;
LookAtMatrix.LookAt( CVector3( 0.0f, 0.0f, 0.0f ), Camera->GetForwardVector(), Camera->GetUpVector() );

The transposed of this look at matrix is then the gizmo rotation, it's always face to the camera.

Then you simply compute the intersection of a plane using forward of the camera as normal, this will gives you the delta for the translation.

I don't have this mode in my editor, I only allow local space and world space, it's common in all game engine.

You can see a screenshot of my actual gizmo here : http://zupimages.net/up/15/46/r5q8.png

The center sphere is the screen space mode, in local space or world space.

Edited by Alundra

Share this post


Link to post
Share on other sites

Simply create the look at matrix like that (from, to, up) or hardcode directly the matrix to avoid to transpose :

CMatrix4 LookAtMatrix;
LookAtMatrix.LookAt( CVector3( 0.0f, 0.0f, 0.0f ), Camera->GetForwardVector(), Camera->GetUpVector() );

The transposed of this look at matrix is then the gizmo rotation, it's always face to the camera.

Then you simply compute the intersection of a plane using forward of the camera as normal, this will gives you the delta for the translation.

I don't have this mode in my editor, I only allow local space and world space, it's common in all game engine.

You can see a screenshot of my actual gizmo here : http://zupimages.net/up/15/46/r5q8.png

The center sphere is the screen space mode, in local space or world space.

 

Hi, thanks for the response

 

I did try that and whilst it does align the rotation with the screen when the object is in the centre of the screen, you still end up with perspective skewing when you move the camera:

 

http://s475.photobucket.com/user/Purpl3Ha2e/media/Gizmo/Image1.jpg.html

 

http://s475.photobucket.com/user/Purpl3Ha2e/media/Gizmo/Image2.jpg.html

 

The first image shows the object selected whilst in the centre, and the second shows the camera moved to the side.  Although the rotation of the gizmo is correct, the perspective of the camera is skewing the gizmo.  Should I be rendering the widgets using an ortho projection?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!