Skip to content

Commit

Permalink
Merge pull request #9 from dipsywong98/dynamic-arm
Browse files Browse the repository at this point in the history
dynamic number of arm segments
  • Loading branch information
dipsywong98 authored Mar 19, 2019
2 parents a042021 + 4bd4e5e commit 3cfdf2a
Show file tree
Hide file tree
Showing 6 changed files with 461 additions and 454 deletions.
4 changes: 2 additions & 2 deletions MyModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void MyModel::draw()
drawSphere(0.5);
glPopMatrix();

std::vector<double> angles{ 0,0,0,0,0,0 };
std::vector<double> angles(2*(int)VAL(ARMCNT));
IkSolver ik;
ik.baseHeight = VAL(HEIGHT);
ik.minangle = VAL(IKMIN);
Expand Down Expand Up @@ -210,7 +210,7 @@ void MyModel::draw()
{
glPushMatrix();
glTranslated(0, VAL(HEIGHT), 0);
drawArm(3);
drawArm((int)VAL(ARMCNT));
glPopMatrix();
}
}
Expand Down
197 changes: 99 additions & 98 deletions camera.h
Original file line number Diff line number Diff line change
@@ -1,99 +1,100 @@
// This camera stuff mostly by ehsu

#ifndef CAMERA_H
#define CAMERA_H

#include "vec.h"
#include "mat.h"

//==========[ class Camera ]===================================================

typedef enum { kActionNone, kActionTranslate, kActionRotate, kActionZoom, kActionTwist,} MouseAction_t;

class Camera {

protected:

float mElevation;
float mAzimuth;
float mDolly;
float mTwist; // Not implemented yet

Vec3f mLookAt;

Vec3f mPosition;
Vec3f mUpVector;
bool mDirtyTransform;

void calculateViewingTransformParameters();

Vec3f mLastMousePosition;
MouseAction_t mCurrentMouseAction;
int lastScroll;


public:

//---[ Constructors ]----------------------------------

// defaults to (0,0,0) facing down negative z axis
Camera();

//---[ Settings ]--------------------------------------

inline void setElevation( float elevation )
{
// don't want elevation to be negative
if (elevation<0) elevation+=6.28318530717f;
mElevation = elevation; mDirtyTransform = true;
}
inline float getElevation() const
{ return mElevation; }

inline void setAzimuth( float azimuth )
{ mAzimuth = azimuth; mDirtyTransform = true; }
inline float getAzimuth() const
{ return mAzimuth; }

inline void setDolly( float dolly )
{ mDolly = dolly; mDirtyTransform = true; }
inline float getDolly() const
{ return mDolly; }

inline void setTwist( float twist )
{ mTwist = twist; mDirtyTransform = true; }
inline float getTwist() const
{ return mTwist; }

inline void setLookAt( const Vec3f &lookAt )
{ mLookAt = lookAt; mDirtyTransform = true;}
inline Vec3f getLookAt() const
{ return mLookAt; }

inline void frameAll()
{
mElevation = 6.7054;
mAzimuth = 2.7193;
mDolly = -30;
mLookAt = Vec3<float>(0.5, 2, -0.5);
mPosition = Vec3<float>(-9.5, 15, 21.5);
mDirtyTransform = true;
}

//---[ Interactive Adjustment ]------------------------
// these should be used from a mouse event handling routine that calls
// the startX method on a mouse down, updateX on mouse move and finally
// endX on mouse up.
//-----------------------------------------------------
void clickMouse( MouseAction_t action, int x, int y );
void dragMouse( int x, int y );
void releaseMouse( int x, int y );

//---[ Viewing Transform ]--------------------------------
void applyViewingTransform();

// gluLookAt equivalent
void lookAt(Vec3f eye, Vec3f at, Vec3f up);
};

// This camera stuff mostly by ehsu

#ifndef CAMERA_H
#define CAMERA_H

#include "modelerglobals.h"
#include "vec.h"
#include "mat.h"

//==========[ class Camera ]===================================================

typedef enum { kActionNone, kActionTranslate, kActionRotate, kActionZoom, kActionTwist,} MouseAction_t;

class Camera {

protected:

float mElevation;
float mAzimuth;
float mDolly;
float mTwist; // Not implemented yet

Vec3f mLookAt;

Vec3f mPosition;
Vec3f mUpVector;
bool mDirtyTransform;

void calculateViewingTransformParameters();

Vec3f mLastMousePosition;
MouseAction_t mCurrentMouseAction;
int lastScroll;


public:

//---[ Constructors ]----------------------------------

// defaults to (0,0,0) facing down negative z axis
Camera();

//---[ Settings ]--------------------------------------

inline void setElevation( float elevation )
{
// don't want elevation to be negative
if (elevation<0) elevation+=6.28318530717f;
mElevation = elevation; mDirtyTransform = true;
}
inline float getElevation() const
{ return mElevation; }

inline void setAzimuth( float azimuth )
{ mAzimuth = azimuth; mDirtyTransform = true; }
inline float getAzimuth() const
{ return mAzimuth; }

inline void setDolly( float dolly )
{ mDolly = dolly; mDirtyTransform = true; }
inline float getDolly() const
{ return mDolly; }

inline void setTwist( float twist )
{ mTwist = twist; mDirtyTransform = true; }
inline float getTwist() const
{ return mTwist; }

inline void setLookAt( const Vec3f &lookAt )
{ mLookAt = lookAt; mDirtyTransform = true;}
inline Vec3f getLookAt() const
{ return mLookAt; }

inline void frameAll(double e)
{
mElevation = 6.7054;
mAzimuth = 2.7193;
mDolly = -10*e;
mLookAt = Vec3<float>(0.5, 2, -0.5);
mPosition = Vec3<float>(-3.5, 5, 7.5);
mDirtyTransform = true;
}

//---[ Interactive Adjustment ]------------------------
// these should be used from a mouse event handling routine that calls
// the startX method on a mouse down, updateX on mouse move and finally
// endX on mouse up.
//-----------------------------------------------------
void clickMouse( MouseAction_t action, int x, int y );
void dragMouse( int x, int y );
void releaseMouse( int x, int y );

//---[ Viewing Transform ]--------------------------------
void applyViewingTransform();

// gluLookAt equivalent
void lookAt(Vec3f eye, Vec3f at, Vec3f up);
};

#endif
20 changes: 11 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ int main()
controls[ZPOS] = ModelerControl("Z Position", -5, 5, 0.1f, 0);
controls[HEIGHT] = ModelerControl("Height", 1, 2.5, 0.1f, 1);
controls[ROTATE] = ModelerControl("Rotate", -135, 135, 1, 0);
controls[ARM1V] = ModelerControl("Arm1 Vertical Axis Rotation", -180, 180, 1, 0);
controls[ARM1H] = ModelerControl("Arm1 Horizontal Axis Rotation", -90, 90, 1, 0);
controls[ARM2V] = ModelerControl("Arm2 Vertical Axis Rotation", -180, 180, 1, 0);
controls[ARM2H] = ModelerControl("Arm2 Horizontal Axis Rotation", -90, 90, 1, 0);
controls[ARM3V] = ModelerControl("Arm3 Vertical Axis Rotation", -180, 180, 1, 0);
controls[ARM3H] = ModelerControl("Arm3 Horizontal Axis Rotation", -90, 90, 1, 0);
controls[ARMCNT] = ModelerControl("Arm Amount", 3, 6, 1, 3);
char namebuf[20];
for (int i = 0; i < ARMMAXCNT; i++) {
sprintf(namebuf, "Arm %d Vertical Axis Rotation", i);
controls[ARM1V+2*i] = ModelerControl(namebuf, -180, 180, 1, 0);
sprintf(namebuf, "Arm %d Horizontal Axis Rotation", i);
controls[ARM1H+2*i] = ModelerControl(namebuf, -90, 90, 1, 0);
}
controls[CLAMPWIDTH] = ModelerControl("Clamp Width", 0, 1, 0.01, 0);
controls[LIGHTX] = ModelerControl("Light X", -30, 30, 0.1, -20);
controls[LIGHTY] = ModelerControl("Light Y", -30, 30, 0.1, 12);
Expand All @@ -65,9 +67,9 @@ int main()
controls[BALLJOINTS] = ModelerControl("Ball joints", 0, 1,1, 1);
controls[BOXARMS] = ModelerControl("Box Arms", 0, 1,1, 0);
controls[IKENABLE] = ModelerControl("IK: enable", 0, 1,1, 0);
controls[IKX] = ModelerControl("IK: X", -10, 10,0.01, 3);
controls[IKY] = ModelerControl("IK: Y", -10, 10,0.01, 3);
controls[IKZ] = ModelerControl("IK: Z", -10, 10,0.01, 3);
controls[IKX] = ModelerControl("IK: X", -20, 20,0.01, 3);
controls[IKY] = ModelerControl("IK: Y", -20, 20,0.01, 3);
controls[IKZ] = ModelerControl("IK: Z", -20, 20,0.01, 3);
controls[IKMIN] = ModelerControl("IK: Min", -180, 180,1, -90);
controls[IKMAX] = ModelerControl("IK: Max", -180, 180,1, 90);
controls[SHOWPRISM] = ModelerControl("Show Prism", 0, 1, 1, 0);
Expand Down
4 changes: 3 additions & 1 deletion modelerglobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
enum SampleModelControls
{
XPOS, YPOS, ZPOS, HEIGHT, ROTATE,
ARM1V, ARM1H, ARM2V, ARM2H, ARM3V, ARM3H, CLAMPWIDTH,
ARM1V, ARM1H, ARM2V, ARM2H, ARM3V, ARM3H, ARM4V, ARM4H, ARM5V, ARM5H, ARM6V, ARM6H,
CLAMPWIDTH, ARMCNT,
LIGHTX, LIGHTY, LIGHTZ, LIGHT_3_PT, LEVELDETAILS,
ENABLEANIM, CYCLINGMOOD,
LDISP, LDEPTH, LANGLE, LLEN, LTHICKNESS, LDECAYTHICKNESS, LDECAYLENGTH,
Expand All @@ -27,6 +28,7 @@ enum SampleModelControls
#define COLOR_RED 1.0f, 0.0f, 0.0f
#define COLOR_GREEN 0.0f, 1.0f, 0.0f
#define COLOR_BLUE 0.0f, 0.0f, 1.0f
#define ARMMAXCNT 6

// We'll be getting the instance of the application a lot;
// might as well have it as a macro.
Expand Down
Loading

0 comments on commit 3cfdf2a

Please sign in to comment.