Created
February 25, 2013 21:16
-
-
Save num3ric/5033396 to your computer and use it in GitHub Desktop.
Quaternion interpolation test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cinder/app/AppNative.h" | |
#include "cinder/gl/gl.h" | |
#include "cinder/Quaternion.h" | |
#include "cinder/Timeline.h" | |
#include "cinder/MayaCamUI.h" | |
using namespace ci; | |
using namespace ci::app; | |
using namespace std; | |
class QuatTestApp : public AppNative { | |
public: | |
void setup(); | |
void keyDown( KeyEvent event ); | |
void mouseDown( MouseEvent event ); | |
void mouseDrag( MouseEvent event ); | |
void resize(); | |
void update(); | |
void draw(); | |
private: | |
Quatf mStartQuat, mEndQuat; | |
Anim<Quatf> mCube1Rotation; | |
Quatf mCube2Rotation; | |
MayaCamUI mMayaCam; | |
TimelineRef mTimeline; | |
float mTimestep; | |
}; | |
void QuatTestApp::setup() | |
{ | |
mStartQuat = Quatf( 0.0f, 0.0f, 1.0f, 0.0f); | |
mEndQuat = Quatf( M_PI, 2.5f, 0.83f); | |
mCube1Rotation = mCube2Rotation = mStartQuat; | |
mTimestep = 1.0f; | |
mTimeline = Timeline::create(); | |
gl::enableDepthRead(); | |
} | |
void QuatTestApp::keyDown( KeyEvent event ) | |
{ | |
mTimestep = 0.0f; | |
if( event.getChar() == ' ' ) { | |
mTimeline->apply( &mCube1Rotation, mStartQuat, mEndQuat, 1.0f ); | |
} | |
} | |
void QuatTestApp::mouseDown( MouseEvent event ) | |
{ | |
mMayaCam.mouseDown( event.getPos() ); | |
} | |
void QuatTestApp::mouseDrag( MouseEvent event ) | |
{ | |
mMayaCam.mouseDrag( event.getPos(), event.isLeftDown(), event.isMiddleDown(), event.isRightDown() ); | |
} | |
void QuatTestApp::resize() | |
{ | |
CameraPersp cam = mMayaCam.getCamera(); | |
cam.setAspectRatio( getWindowAspectRatio() ); | |
mMayaCam.setCurrentCam( cam ); | |
} | |
void QuatTestApp::update() | |
{ | |
float step = 0.005f; | |
mTimeline->step( step ); | |
if( mTimestep < 1.0f ) { | |
mTimestep += step; | |
mCube2Rotation = mStartQuat.lerp(mTimestep, mEndQuat); | |
} | |
} | |
void QuatTestApp::draw() | |
{ | |
gl::clear( Color( 0, 0, 0 ) ); | |
gl::setMatrices( mMayaCam.getCamera() ); | |
gl::pushModelView(); | |
gl::translate(-10.f, 0, 0); | |
gl::rotate( mCube1Rotation.value() ); | |
gl::drawColorCube(Vec3f(0,0,0), Vec3f(10.0f, 10.0f, 10.0f)); | |
gl::popModelView(); | |
gl::pushModelView(); | |
gl::translate(10.f, 0, 0); | |
gl::rotate( mCube2Rotation ); | |
gl::drawColorCube(Vec3f(0,0,0), Vec3f(10.0f, 10.0f, 10.0f)); | |
gl::popModelView(); | |
} | |
CINDER_APP_NATIVE( QuatTestApp, RendererGl ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment