Permalink
Browse files

added panning

  • Loading branch information...
1 parent a2c4a35 commit 032e2bd0c7208d4203ae952706fececa038955b0 @TheBuzzSaw committed Mar 22, 2012
Showing with 59 additions and 14 deletions.
  1. +25 −3 CanvasOpenGL.cpp
  2. +1 −1 CanvasOpenGL.hpp
  3. +1 −1 CardActor.cpp
  4. +1 −0 CardActor.hpp
  5. +5 −8 CardModel.cpp
  6. +9 −1 CardModel.hpp
  7. +15 −0 TrackballCamera.cpp
  8. +2 −0 TrackballCamera.hpp
View
@@ -96,6 +96,12 @@ void CanvasOpenGL::mousePressEvent(QMouseEvent* inEvent)
switch (inEvent->button())
{
case Qt::LeftButton:
+ if (mMouseMode == None)
+ {
+ mAnchorX = inEvent->x();
+ mAnchorY = inEvent->y();
+ mMouseMode = PanCamera;
+ }
break;
case Qt::MiddleButton:
@@ -107,7 +113,7 @@ void CanvasOpenGL::mousePressEvent(QMouseEvent* inEvent)
{
mAnchorX = inEvent->x();
mAnchorY = inEvent->y();
- mMouseMode = MoveCamera;
+ mMouseMode = RotateCamera;
}
break;
@@ -123,14 +129,16 @@ void CanvasOpenGL::mouseReleaseEvent(QMouseEvent* inEvent)
switch (inEvent->button())
{
case Qt::LeftButton:
+ if (mMouseMode == PanCamera)
+ mMouseMode = None;
break;
case Qt::MiddleButton:
qDebug() << "middle button";
break;
case Qt::RightButton:
- if (mMouseMode == MoveCamera)
+ if (mMouseMode == RotateCamera)
mMouseMode = None;
break;
@@ -143,7 +151,7 @@ void CanvasOpenGL::mouseMoveEvent(QMouseEvent* inEvent)
{
switch (mMouseMode)
{
- case MoveCamera:
+ case RotateCamera:
{
const float Step = 0.5f;
float deltaX = float(inEvent->x() - mAnchorX) * Step;
@@ -158,6 +166,20 @@ void CanvasOpenGL::mouseMoveEvent(QMouseEvent* inEvent)
break;
}
+ case PanCamera:
+ {
+ const float Step = 0.1f;
+ float deltaX = float(inEvent->x() - mAnchorX) * Step;
+ float deltaY = float(inEvent->y() - mAnchorY) * Step;
+
+ mAnchorX = inEvent->x();
+ mAnchorY = inEvent->y();
+
+ mCamera.smartPan(-deltaX, deltaY);
+
+ break;
+ }
+
default:
break;
}
View
@@ -29,7 +29,7 @@ protected slots:
virtual void wheelEvent(QWheelEvent* inEvent);
private:
- enum { None, MoveCamera } mMouseMode;
+ enum { None, RotateCamera, PanCamera } mMouseMode;
int mAnchorX;
int mAnchorY;
View
@@ -4,7 +4,7 @@
CardActor::CardActor(CardModel& inCardModel, GLuint inFrontTexture,
GLuint inBackTexture)
: mCardModel(inCardModel), mFrontTexture(inFrontTexture),
- mBackTexture(inBackTexture), mFlip(0.0f)
+ mBackTexture(inBackTexture), mRotation(0.0f), mFlip(0.0f)
{
}
View
@@ -31,6 +31,7 @@ class CardActor : public Actor
bool mDrawFront;
vec3f mPosition;
+ float mRotation;
float mFlip;
};
View
@@ -1,7 +1,7 @@
#include "CardModel.hpp"
#include <QDebug>
-CardModel::CardModel()
+CardModel::CardModel() : mWidth(6.3f), mHeight(8.8f), mDepth(0.05f)
{
assemble();
}
@@ -43,12 +43,9 @@ void CardModel::drawEdge()
void CardModel::assemble()
{
- float inWidth = 6.3f;
- float inHeight = 8.8f;
-
- float w = inWidth / 2.0f;
- float h = inHeight / 2.0f;
- float d = 0.05 / 2.0f;
+ float w = mWidth / 2.0f;
+ float h = mHeight / 2.0f;
+ float d = mDepth / 2.0f;
GLfloat points[24] = {
+w, +h, +d,
@@ -74,7 +71,7 @@ void CardModel::assemble()
1.0f, 1.0f
};
- float ratio = inWidth / inHeight;
+ float ratio = mWidth / mHeight;
float adjustment = 490.0f / 512.0f; // card image size adjustment
for (size_t i = 0; i < 8; ++i)
{
View
@@ -13,9 +13,17 @@ class CardModel
void drawBack(GLuint inTexture);
void drawEdge();
- void assemble();
+ inline float width() const { return mWidth; }
+ inline float height() const { return mHeight; }
+ inline float depth() const { return mDepth; }
private:
+ void assemble();
+
+ float mWidth;
+ float mHeight;
+ float mDepth;
+
VertexBufferObject mVertexBuffer;
VertexBufferObject mTextureBuffer;
IndexBufferObject mTopIndexBuffer;
View
@@ -20,6 +20,21 @@ void TrackballCamera::update()
mMatrix.translate(-mPosition[0], -mPosition[1], -mPosition[2]);
}
+void TrackballCamera::smartPan(float inX, float inY)
+{
+ float theta = mRotation * 3.141592654f / 180.0f;
+ float c = cos(theta);
+ float s = sin(theta);
+
+ float deltaX = c * inX;
+ float deltaY = -s * inX;
+ deltaX += s * inY;
+ deltaY += c * inY;
+
+ mPosition[0] += deltaX;
+ mPosition[1] += deltaY;
+}
+
void TrackballCamera::setPosition(const vec3f& inPosition)
{
mPosition = inPosition;
View
@@ -14,6 +14,8 @@ class TrackballCamera
void update();
+ void smartPan(float inX, float inY);
+
void setPosition(const vec3f& inPosition);
void changePosition(const vec3f& inDelta);

0 comments on commit 032e2bd

Please sign in to comment.