Jump to content

Get rotation of camera


DezOnlyOne
 Share

Recommended Posts

I have an application where I have an FPS like camera that moves around a scene. I want to be able to use a camTo function to move the player around the scene. I have a position v3 and target v3. If I do not have a rotation value, the camera is not looking at the target. Is there a way to calculate the rotation knowing the position of the camera and the position of the target. Is my approach to this incorrect? How do I correctly move my freecamera to the correct location and ensure that it is looking at my desired target?

Link to comment
Share on other sites

There are ways to do this without caring about all that.  Either use a followCamera (third person camera), or a subclass of TargetCamera (practically all but ArcRotateCamera) & set the target.

There is some trigonometry to assign rotation to camera, but I do not understand why you would move your camera to the "correct" location.  If it is a first person camera, the user has already moved it to where they want to view from.

Link to comment
Share on other sites

47 minutes ago, JCPalmer said:

There are ways to do this without caring about all that.  Either use a followCamera (third person camera), or a subclass of TargetCamera (practically all but ArcRotateCamera) & set the target.

There is some trigonometry to assign rotation to camera, but I do not understand why you would move your camera to the "correct" location.  If it is a first person camera, the user has already moved it to where they want to view from.

Sorry, I can explain further. The user can walk around in a big warehouse and view whatever they want, but if they want to move quickly to a specific object instead of "walking" over, or up stairs, they can select the object from an index that will make them appear in front of the object. Does this make sense? 

Link to comment
Share on other sites

Ok, FreeCamera is a subclass of TargetCamera.  After you change the camera location, you could set the target to what you want to look at.  Sounds like you would only want to do that for one frame.

Putting something to change one frame later is a pain. Try:
 

camera.lockedTarget = lookAtMesh;
camera._getViewMatrix();
camera.lockedTarget = null;

 

Link to comment
Share on other sites

Sorry, I spoke too soon. After testing a little further I realized this is not working correctly. Part of the room I have is a spiral ramp with several plaques on the wall. As you are transported to each of the plaques, I notice that the target is getting further and further away. 

I setup a babylonjs playground with 4 spheres as targets, and 4 boxes as their corresponding camera positions. The camTo function works fine to move the camera position. I just need to be able to look at the ball. You can uncomment which ever POV you want to use at the bottom. When you load this, you won't see anything because the ball(and other objects are behind you. but if you just hit the down arrow to back up or turn around with the mouse drag, you will see that it is there.

 

http://www.babylonjs-playground.com/#Y7QTM#3

 

Thanks for all your help

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...