Ignore:
Timestamp:
10/29/08 10:19:11 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

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

    r3062 r3078  
    11#include "Matrix4x4.h" 
    22#include "Vector3.h" 
    3  
    4 // standard headers 
    53#include "AxisAlignedBox3.h" 
    6 #include <iomanip> 
     4 
    75 
    86using namespace std; 
     7 
    98 
    109namespace CHCDemoEngine  
     
    625624                for (int j = 0; j < 4; j++) { // x 
    626625                        //  x  y  
    627                         s << setprecision(4) << setw(10) << M.x[j][i]; 
     626                        s << M.x[j][i]; 
    628627                } 
    629628                s << '\n'; 
  • 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 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/MotionPath.h

    r2951 r3078  
    3434        void Reset(); 
    3535 
     36        Matrix4x4 GetOrientation(); 
     37 
    3638 
    3739protected: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3077 r3078  
    5454#include "Texture.h" 
    5555#include "ShaderManager.h" 
     56#include "MotionPath.h" 
    5657 
    5758 
     
    103104SkyPreetham *preetham = NULL; 
    104105 
     106MotionPath *motionPath = NULL; 
    105107 
    106108 
     
    142144 
    143145int shadowSize = 2048; 
    144  
    145146/// the hud font 
    146147glfont::GLFont myfont; 
     
    276277/// Creates the traversal method (vfc, stopandwait, chc, chc++) 
    277278RenderTraverser *CreateTraverser(PerspectiveCamera *cam); 
    278  
    279279/// place the viewer on the floor plane 
    280280void PlaceViewer(const Vector3 &oldPos); 
     
    293293inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 
    294294 
     295void CreateAnimation(); 
     296 
     297 
    295298// the new and the old viewProjection matrix of the current camera 
    296299static Matrix4x4 viewProjMat = IdentityMatrix(); 
     
    455458        //-- load some dynamic stuff 
    456459 
    457         /*LoadModel("hbuddha.dem", dynamicObjects); 
     460        LoadModel("hbuddha.dem", dynamicObjects); 
    458461        buddha = dynamicObjects.back(); 
    459462         
     
    479482        } 
    480483 
    481 */ 
     484 
    482485        /////////// 
    483486        //-- load the associated static bvh 
     
    512515        const float turbitiy = 5.0f; 
    513516        preetham = new SkyPreetham(turbitiy, skyDome); 
     517 
     518        CreateAnimation(); 
    514519 
    515520 
     
    870875void MainLoop()  
    871876{        
    872         /*Vector3 offs = Vector3::ZERO(); 
    873         offs.x = RandomValue(-.1f, .1f); 
    874         offs.y = RandomValue(-.1f, .1f); 
    875         //offs.x = RandomValue(.0f, .01f); 
    876         //offs.y = RandomValue(.0f, .01f); 
    877  
    878         Matrix4x4 mat = TranslationMatrix(offs); 
    879         buddha->GetTransform()->MultMatrix(mat); 
    880 */ 
     877        motionPath->Move(0.3f); 
     878 
     879        Vector3 planepos = motionPath->GetCurrentPosition(); 
     880 
     881        Matrix4x4 mat = TranslationMatrix(planepos); 
     882        buddha->GetTransform()->SetMatrix(mat); 
     883 
    881884        Vector3 oldPos = camera->GetPosition(); 
    882885 
     
    16731676        DEL_PTR(shadowMap); 
    16741677        DEL_PTR(shadowTraverser); 
     1678        DEL_PTR(motionPath); 
    16751679 
    16761680        ResourceManager::DelSingleton(); 
     
    20442048        } 
    20452049} 
     2050 
     2051 
     2052void CreateAnimation() 
     2053{ 
     2054        const float radius = 5.0f; 
     2055        const Vector3 center(483.398f, 242.364f, 186.078f); 
     2056 
     2057        VertexArray vertices; 
     2058 
     2059        for (int i = 0; i < 360; ++ i) 
     2060        { 
     2061                float angle = (float)i * M_PI / 180.0f; 
     2062 
     2063                Vector3 offs = Vector3(cos(angle) * radius, sin(angle) * radius, 0); 
     2064                vertices.push_back(center + offs); 
     2065        } 
     2066 
     2067        motionPath = new MotionPath(vertices); 
     2068} 
Note: See TracChangeset for help on using the changeset viewer.