How do I point the 3d camera the direction of a 3D object with euler rotation?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • Hi there, I've been successful in getting a 3D object to rotate on the different X,Y,Z axis but I'm wanting the 3D camera to match the rotation.

    I'm trying to do a demo of a plane flying, so I'm wanting the camera to tilt up and down, as well as lean left and right for turning.

    I've got the 3D object to do all these actions just fine but am having trouble getting the 3D camera Look At Position to match what I want to do. Anyone know how I can achieve this?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Since there's no easy action to calculate the way you want it to you have to use this math to calculate it.

    For a plane that pitches and rolls in true 3D, create three invisible child objects attached to the plane:

    - CameraAnchor: behind and above the plane

    - AimAnchor: in front of the plane

    - UpAnchor: above the camera

    Then every tick--------------------------------------------------------

    3D Camera: Look at position

    Camera:

    CameraAnchor.X, CameraAnchor.Y, CameraAnchor.Z

    Look at:

    AimAnchor.X, AimAnchor.Y, AimAnchor.Z

    Up vector:

    UpAnchor.X - CameraAnchor.X

    UpAnchor.Y - CameraAnchor.Y

    UpAnchor.Z - CameraAnchor.Z

  • I've got the 3D object to do all these actions just fine but am having trouble getting the 3D camera Look At Position to match what I want to do. Anyone know how I can achieve this?

    Hello.

    Give me a file (*.c3p) with the plane, I will attach a camera to it. And I will comment on the code.

  • One way could be to have a dummy 3d object that you rotate (since you said you have been able to do that).

    Then just set the 3dcamera’s orientation from that object’s orientation.

    The main issue is there are three ways to specify 3d orientation: Euler, quaternion, and 3x3matrix. Most objects let you use Euler and quaternion, but with the camera you can only set the orientation in a general way with the look at action which basically takes a 3x3matrix.

    You can convert between the different orientation representations with some math that you can find online. For example:

    euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/index.htm

    So say you have an object’s orientation as a quaternion (qx,qy,qz,qw) which there are expressions for. Then you can convert it to a 3x3 matrix. In the matrix the second row would be the up vector, and the third row would be the forward or basically the look at vector if you add the camera position.

    So the parameters for the look at action should be:

    Camera x = self.x
    Camera y = self.y
    Camera z = self.z
    Look x = 2*qx*qz - 2*qy*qw +self.x
    Look y = 2*qy*qz + 2*qx*qw +self.y
    Look z = 1 - 2*qx^2 - 2*qy^2 +self.z
    Up x = 2*qx*qy + 2*qz*qw
    Up y = 1 - 2*qx^2 - 2*qz^2
    Up z = 2*qy*qz - 2*qx*qw

    The qx means 3dobject.QuaternionX In those expressions if that’s not clear. Same for qy, qz and qw.

    Anyways, barring any typos on my part or some oddity in c3 then that should work.

    You could also convert between Euler and matrix instead. But you’d have to try different rotation orders if c3 rotates xyz in different orders than the formulas.

    Maybe c3 will hide the complexity at a later date and just let you set the camera’s orientation from another object, or just give everything the same rotation tools. But short term things seem to look more and more cluttered to me.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)