help with look_at

takedabro1takedabro1 Posts: 7Member
in 3D

how exactly do i use the look_at function, and what is the target : vector3 and up:vector3 variables?

Comments

  • MegalomaniakMegalomaniak Posts: 2,785Admin

    up vector 3 defines the floor/up orientation and the target should be the position/object to look at.

  • TwistedTwiglegTwistedTwigleg Posts: 2,873Admin

    Just a quick note: The target position needs to be in global space! Also, the look_at function will return a rotated transform where the Z axis is facing the target, regardless of the initial rotation of the transform, so you will need to make your objects either face the Z axis, or apply additional rotation so the correct axis is facing forward.

  • KequcKequc Posts: 122Member
    edited July 26

    @Megalomaniak said:
    up vector 3 defines the floor/up orientation and the target should be the position/object to look at.

    Why is the up parameter necessary? Is it to prevent the object that's looking from getting into a weird orientation somehow?

  • MegalomaniakMegalomaniak Posts: 2,785Admin

    Probably, or to avoid gimbal locking perhaps?

  • Green BaronGreen Baron Posts: 26Member
    edited July 26

    The up vector defines one of the axes of the camera coordinate system. The other one being the vector from camera position to target position. The third, which points left or right, is trivially calculated by crossing the two. By choosing an up-vector of (0,1,0) your camera is aligned with world up (+y). By choosing e.g. (0,-1,0) things would be upside down. Without an up vector the camera orientation could not be calculated.

    But also read the 3D math intro in the docs and it's hints concerning tranforms and gimbal lock.

  • MegalomaniakMegalomaniak Posts: 2,785Admin

    Yeah, one use would be if you want to traverse the surface of a sphere for an example.

  • Green BaronGreen Baron Posts: 26Member
    edited July 26

    Exactly. The up vector would then be -(sphere center - camera position) and best be normalized if i am not too confused, which definitely can not be excluded with 100% confidence ...

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file