Ignore:
Timestamp:
10/29/08 10:19:11 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/MotionPath.cpp

    r2953 r3078  
    11#include "MotionPath.h" 
     2#include "Matrix4x4.h" 
    23 
    34 
     
    78 
    89MotionPath::MotionPath(const VertexArray &vertices): 
    9 mVertices(vertices), mCurrentVertexIdx(0) 
     10mVertices(vertices), mCurrentVertexIdx(0), mT(.0f) 
    1011{ 
    1112} 
     
    1415void MotionPath::Move(float velocity) 
    1516{ 
     17        mT += velocity; 
     18 
     19        if (mT >= 1.0f) 
     20        { 
     21                mCurrentVertexIdx = (mCurrentVertexIdx + 1) % (int)mVertices.size(); 
     22                mT -= 1.0f; 
     23        } 
    1624} 
    1725 
     
    1927Vector3 MotionPath::GetCurrentPosition() const 
    2028{ 
    21         return mT * mVertices[mCurrentVertexIdx] + (1.0f - mT) * mVertices[(mCurrentVertexIdx + 1) % mVertices.size()]; 
     29        return (1.0f - mT) * mVertices[mCurrentVertexIdx] + mT * mVertices[(mCurrentVertexIdx + 1) % mVertices.size()]; 
    2230} 
    2331 
     
    3240{ 
    3341        mCurrentVertexIdx = 0; 
     42        mT = 0; 
     43} 
     44 
     45 
     46Matrix4x4 MotionPath::GetOrientation() 
     47{ 
     48        Vector3 dir = mVertices[(mCurrentVertexIdx + 1) % mVertices.size()] - mVertices[mCurrentVertexIdx]; 
     49        Vector3 ndir = -Normalize(dir); 
     50 
     51        float pitch = -atan2(ndir.x, ndir.y); 
     52        float yaw = atan2(ndir.z, sqrt((ndir.x * ndir.x) + (ndir.y * ndir.y))); 
     53 
     54         
     55        Matrix4x4 roty = RotationYMatrix(pitch); 
     56        Matrix4x4 rotx = RotationXMatrix(yaw); 
     57 
     58        return roty * rotx; 
    3459} 
    3560 
Note: See TracChangeset for help on using the changeset viewer.