Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualKryzon

Posted 23 June 2013 - 05:53 PM

Creating the mesh quad should be more straightforward, like you said.

 

The following was taken from user Floyd of the BlitzBasic forums. Say that the vector from Point 1 to Point 2 describes the Z axis of the quad, and say that the Y axis of this quad is aligned to the mesh normal (so the Y axis is perpendicular to the quad). You can figure global Pitch (X) and Yaw (Y) rotation values from these axes.

We need to find the Roll (Z) value.

 

A way to find this Roll (Z) rotation value for the quad to face the camera is to imagine that this value will make the quad place the camera in this quad's ZY plane.

There may be some negations needed based on what you consider as positive or negative sides, angles etc., but the logic is here.

 

2ps3ymg.png

 

To do the above, you need to get the camera's position in the quad's local space. Store it in a vector like "cameraLocalPos".

Then you can find the global Roll (Z) value for the quad with this: roll = ATan2( cameraLocalPos.X, cameraLocalPos.Y )

Note the inversion of the ATan2 parameters since we want the angle relative to the Y axis rather than the usual X axis.

 

Then rotate the quad in global coordinates by the following: Quad.Rotate( GlobalPItch, GlobalYaw, roll ).


#1Kryzon

Posted 23 June 2013 - 05:40 PM

Creating the mesh quad should be more straightforward, like you said.

 

The following was taken from user Floyd of the BlitzBasic forums. Say that the vector from Point 1 to Point 2 describes the Z axis of the quad, and say that the Y axis of this quad is aligned to the mesh normal (so the Y axis is perpendicular to the quad).

 

In order to care for the billboarding, you need to roll that quad around its Z axis so that this quad makes the camera be located in its ZY plane.

There may be some negations needed based on what you consider as positive or negative sides, angles etc., but the logic is there.

 

2ps3ymg.png

 

To do the above, you need to get the camera's position in the quad's local space. Store it in a vector like "cameraLocalPos".

Then you rotate the quad locally around its Z axis by the following angle: ATan2( cameraLocalPos.X, cameraLocalPos.Y )

Note the inversion of the ATan2 parameters since we want the angle relative to the Y axis rather than the usual X axis.


PARTNERS