Vector2Rotation – ShiVa Engine

Vector2Rotation

Rotations are global, based on the current position of V2R_OriginObject. nDot allows to you to easily determine if V2R_TargetObject is within the Frustum of V2R_OriginObject (within its forward view) If nDot is greater than 0.8 (on a scale of 0.0 to 1.0), then it is probably within the forward view of V2R_OriginObject.
Format: RotationX, RotationY, RotationZ, nDot = this.Vector2Rotation ( V2R_OriginObject, V2R_TargetObject)

--------------------------------------------------------------------------------
--  Function......... : Vector2Rotation
--  Author........... :
--  Description...... :
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function TEST_ClickAndGo_Character.Vector2Rotation ( V2R_OriginObject, V2R_TargetObject)
--------------------------------------------------------------------------------
    -- Get Scene
    local hScene = application.getCurrentUserScene ( )
    -- Get V2R_OriginObject position and rotation.
    local x, y, z = object.getTranslation ( V2R_OriginObject, object.kGlobalSpace )
    local vx, vy, vz = object.getDirection ( V2R_OriginObject, object.kGlobalSpace )
    -- Get V2R_TargetObject postion.
    local seex, seey, seez = object.getTranslation ( V2R_TargetObject, object.kGlobalSpace  )
--------------------------------------------------------------------------------
    -- Calculate normalized (reduced to '1') relative vector
    local nx, ny, nz = math.vectorNormalize ( seex - x, seey - y, seez - z )
    -- Calculate nDot
    local nDot = math.vectorDotProduct ( vx, vy, vz, nx, ny, nz )
    -- All this returns the the global rotation to target from V2R_OriginObject postion, and the nDot for Frustum...
    return nx, ny, nz, nDot
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------



Need more answers?

  • slackBanner