Skip to content

Instantly share code, notes, and snippets.

@sansumbrella
Created September 3, 2014 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansumbrella/b0294b59131e2903f165 to your computer and use it in GitHub Desktop.
Save sansumbrella/b0294b59131e2903f165 to your computer and use it in GitHub Desktop.
Roll/Pitch/Yaw weird
#include "cinder/app/AppNative.h"
#include "cinder/gl/gl.h"
#include "cinder/Camera.h"
#include "cinder/params/Params.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class CameraTestApp : public AppNative {
public:
void setup();
void mouseDown( MouseEvent event );
void update();
void draw();
private:
ci::CameraPersp mCamera;
float mPitch = 0.0f;
float mYaw = 0.0f;
float mRoll = 0.0f;
ci::params::InterfaceGlRef mParams;
};
void CameraTestApp::setup()
{
mCamera.setPerspective( 60.0f, getWindowWidth() / (float)getWindowHeight(), 1.0f, 5000.0f );
mCamera.setEyePoint( Vec3f( 0.0f, 0.0f, 300.0f ) );
mParams = params::InterfaceGl::create( "Camera Stuff", Vec2i( 200, 200 ) );
mParams->addParam( "Pitch", &mPitch ).step( M_PI / 100.0f );
mParams->addParam( "Yaw", &mYaw ).step( M_PI / 100.0f );
mParams->addParam( "Roll", &mRoll ).step( M_PI / 100.0f );
}
void CameraTestApp::mouseDown( MouseEvent event )
{
}
void CameraTestApp::update()
{
Quatf orientation( mPitch, mYaw, mRoll );
mCamera.setOrientation( orientation );
}
void CameraTestApp::draw()
{
// clear out the window with black
gl::clear( Color( 0, 0, 0 ) );
gl::setMatrices( mCamera );
for( int y = -10; y < 10; ++y )
{
for( int x = -10; x < 10; ++x )
{
gl::pushModelView();
gl::color( lmap<float>( y, -10, 10, 0.0f, 1.0f ), 0.5f, 1.0f );
gl::translate( Vec3f( x * 20.0f, y * 20.0f, 0.0f ) );
gl::drawSolidCircle( Vec2f( 0.0f, 0.0f ), 8.0f );
gl::popModelView();
}
}
gl::pushModelView();
gl::translate( Vec3f( -300.0f, 0.0f, 0.0f ) );
gl::rotate( Vec3f( 0.0f, 90.0f, 0.0f ) );
gl::drawSolidRect( Rectf( -200.0f, -200.0f, 200.0f, 200.0f ) );
gl::popModelView();
gl::pushModelView();
gl::translate( Vec3f( 300.0f, 0.0f, 0.0f ) );
gl::rotate( Vec3f( 0.0f, 90.0f, 0.0f ) );
gl::drawSolidRect( Rectf( -200.0f, -200.0f, 200.0f, 200.0f ) );
gl::popModelView();
mParams->draw();
}
CINDER_APP_NATIVE( CameraTestApp, RendererGl )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment