Permalink
Browse files

Merge conflicts

  • Loading branch information...
2 parents affec13 + 2cea896 commit da311b0f780f9490c7d8cfabc1ace107d088720c @eiskalt eiskalt committed Oct 16, 2012
Showing with 53 additions and 26 deletions.
  1. +5 −6 BSpline.cpp
  2. +1 −1 BSpline.h
  3. +3 −4 Camera.cpp
  4. +1 −1 ControlPoint.cpp
  5. +3 −1 ControlPoint.h
  6. +11 −5 Skeleton.cpp
  7. +29 −8 main.cpp
View
@@ -80,8 +80,8 @@ void BSpline::assignColourId() {
//****************************************************************************
// DRAWING
//****************************************************************************
-void BSpline::draw(){
- drawControlPoints(GL_RENDER);
+void BSpline::draw(GLenum mode){
+ drawControlPoints(mode);
drawCurve();
}
@@ -108,8 +108,7 @@ void BSpline::drawControlPoints(GLenum mode) {
}
// draw the control points
for (int i = 0; i < controlPointsNum; i++) {
- //printf("i, pointSelected, point[i]: %i %i %f %f %f\n", i, pointSelected, controlPoints[i].x, controlPoints[i].y, controlPoints[i].z);
- controlPoints[i].draw(pointSelected == i);
+ controlPoints[i].draw(pointSelected == i, mode);
if(infoDisplay) controlPoints[i].showTime();
}
@@ -273,21 +272,21 @@ void BSpline::selectPoint(int x, int y){
glDisable(GL_FOG);
glDisable(GL_LIGHTING);
- drawControlPoints(GL_SELECT);
+ draw(GL_SELECT);
GLint viewport[4];
unsigned char pixel[3];
glGetIntegerv(GL_VIEWPORT, viewport); // get color information from frame buffer
glReadPixels(x, viewport[3] - y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);
- printf("pixel: %i %i %i\n", pixel[0], pixel[1], pixel[2]);
for (int i = 0; i < controlPointsNum; i++) {
if((controlPoints[i].r == pixel[0]) && (controlPoints[i].g == pixel[1]) && (controlPoints[i].b) == pixel[2]){
pointSelected = i;
break;
}
}
+
glutPostRedisplay();
}
View
@@ -60,7 +60,7 @@ class BSpline {
void printArray(float* a, int size);
void assignColourId();
- void draw();
+ void draw(GLenum mode);
void selectPoint(int x, int y);
void deselectPoint();
View
@@ -80,15 +80,14 @@ void Camera::lookAt(BSpline* bs, int m, double winWidth, double winHeight, G308_
pos->y = f.ctrlPoint.y;
pos->z = f.ctrlPoint.z;
+ ref->N = ref->N + f.ctrlPoint;
+ ref->B = ref->B + f.ctrlPoint;
+
if (f.isLast == 1) {
if(m == 1) gluLookAt(f.ctrlPoint.x, f.ctrlPoint.y, f.ctrlPoint.z, 0, 0, 0, ref->B.x, ref->B.y,ref->B.z);
else if(m == 2) gluLookAt(f.ctrlPoint.x, f.ctrlPoint.y, f.ctrlPoint.z, ref->T.x, ref->T.y, ref->T.z, ref->B.x, ref->B.y,ref->B.z);
}
else{
- ref->N = ref->N + f.ctrlPoint;
- ref->B = ref->B + f.ctrlPoint;
-
- //printf("%i\nt: %f %f %f\tB: %f %f %f\n", count++, ref->T.x, ref->T.y, ref->T.z, ref->B.x, ref->B.y,ref->B.z);
if(m == 1) gluLookAt(f.ctrlPoint.x, f.ctrlPoint.y, f.ctrlPoint.z, 0, 0, 0, ref->B.x, ref->B.y,ref->B.z);
else if(m == 2) gluLookAt(f.ctrlPoint.x, f.ctrlPoint.y, f.ctrlPoint.z, ref->T.x, ref->T.y, ref->T.z, ref->B.x, ref->B.y,ref->B.z);
}
View
@@ -53,7 +53,7 @@ void ControlPoint::add(ControlPoint p){
z += p.z;
}
-void ControlPoint::draw(bool pointSelected){
+void ControlPoint::draw(bool pointSelected, GLenum mode){
glPushMatrix();
glColor3f(r / 255.0f, g / 255.0f, b / 255.0f);
if (pointSelected) {
View
@@ -8,6 +8,8 @@
#ifndef CONTROLPOINT_H_
#define CONTROLPOINT_H_
+#include <GL/glut.h>
+
class ControlPoint {
public:
float x,y,z;
@@ -22,7 +24,7 @@ class ControlPoint {
void setColourID(float rr, float gg, float bb);
void multiplyScalar(float);
void add(ControlPoint p);
- void draw(bool pointSelected);
+ void draw(bool pointSelected, GLenum mode);
void showTime();
void unprojectScreenCoord(int x, int y);
void normalize();
View
@@ -33,6 +33,8 @@ Skeleton::Skeleton() {
currentFrameNumber = 0;
buffSize = 200;
maxBones = 60;
+ angle = 0;
+ rotAxis = ControlPoint();
root = (bone*) malloc(sizeof(bone) * maxBones);
for (int i = 0; i < 60; i++) {
@@ -133,15 +135,19 @@ void Skeleton::drawParts(bone* root, GLUquadric* q) {
}
void Skeleton::move(BSpline* bs){
+ printf("Move\n");
Frame f = bs->nextFrame();
+ printf("f: %f %f %f\n", f.ctrlPoint.x, f.ctrlPoint.y, f.ctrlPoint.z);
position = f.ctrlPoint;
+ printf("position: %f %f %f\n", position.x, position.y, position.z);
ControlPoint zVector = ControlPoint(0, 0, 1);
//f.tangent.normalize();
rotAxis = crossProduct(zVector, f.tangent);
angle = dotProduct(zVector, f.tangent);
angle = acos(angle);
angle = angle * (180.0 / 3.1416);
+ printf("a: %f\t axis: %f %f %f\n", angle, rotAxis.x, rotAxis.y, rotAxis.z);
}
void Skeleton::doAMCrotation(bone* bone){
@@ -206,7 +212,7 @@ void Skeleton::drawOnePart(bone* root, GLUquadric* q) {
glRotatef(root->rotx, 1, 0, 0);
glColor3f(0, 1, 1);
- glutSolidSphere(0.1, 100, 100);
+ glutSolidSphere(0.1, 3, 3);
glPopMatrix();
@@ -220,18 +226,18 @@ void Skeleton::drawOnePart(bone* root, GLUquadric* q) {
glRotatef(-root->rotz, 0, 0, 1);
- GLfloat angle = 0.0;
+ GLfloat a = 0.0;
glPushMatrix();
// Find rotation vector normal.
G308_Point v1 = { 0, 0, 1 };
G308_Point v2 = { root->dirx, root->diry, root->dirz };
G308_Point normal = { 0, 0, 0 };
calculateCrossProduct(v1, v2, &normal);
// Find angle of rotation from bone's direction (in degrees).
- angle = calculateDotProduct(v1, v2);
+ a = calculateDotProduct(v1, v2);
glColor3f(1, 1, 1);
- glRotatef(angle, normal.x, normal.y, normal.z);
- gluCylinder(q, 0.05, 0.05, root->length, 10, 10);
+ glRotatef(a, normal.x, normal.y, normal.z);
+ gluCylinder(q, 0.05, 0.05, root->length, 3, 3);
glPopMatrix();
View
@@ -35,6 +35,7 @@ enum MENU_TYPE {
// Assign a default value
MENU_TYPE menu_choice = SIMPLE;
bool choiceChanged = false;
+bool lightsOn = true;
GLuint g_mainWnd;
GLuint g_nWinWidth = G308_WIN_WIDTH;
@@ -227,6 +228,10 @@ void tick (){
//
// If animation is on, move the object one step.
if(animate == 1){
+ if(choiceChanged){
+ choiceChanged = false;
+ bspline->resetFrame();
+ }
switch(menu_choice){
case SIMPLE:
shape->move(bspline);
@@ -238,6 +243,7 @@ void tick (){
camera->lookAt(bspline, 2, (double)g_nWinWidth, (double)g_nWinHeight, &cameraPos);
break;
case SKELETON:
+ if (skeleton != NULL) skeleton->move(bspline);
break;
}
@@ -309,7 +315,7 @@ void G308_display() {
// Draw the spline with the control points
- bspline->draw();
+ bspline->draw(GL_SELECT);
// Draw the shape that goes along the spline if animation is moving.
if(animate == 1){
@@ -409,8 +415,13 @@ void mouse (int b, int s, int x, int y){
// This one is for selecting a control point and changing its position.
if(b == GLUT_LEFT_BUTTON && s == GLUT_DOWN
&& (key_held == MOVE_ALONG_X || key_held == MOVE_ALONG_Y || key_held == MOVE_ALONG_Z)){
+
+ glDisable(GL_LIGHT0);
+ glDisable(GL_LIGHT1);
bspline->selectPoint(x, y);
buttons[0] = ((GLUT_DOWN == s) ? 1 : 0);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_LIGHT1);
}
// Remember that left button is pressed.
else if(b == GLUT_LEFT_BUTTON){
@@ -427,6 +438,7 @@ void mouse (int b, int s, int x, int y){
// Menu items
void menu(int item) {
menu_choice = (MENU_TYPE)item; // CAMERA_ORIGIN, CAMERA_TANGENT, SIMPLE, or SKELETON
+ choiceChanged = true;
switch(item){
case REMOVE_PARTICLES:
@@ -443,8 +455,6 @@ void menu(int item) {
break;
}
- printf("Choice changed\n");
-
glutPostRedisplay();
}
@@ -493,6 +503,7 @@ void G308_keyboardListener(unsigned char key, int x, int y) {
wind[0] = 0.1f;
particeEmitter->applyWind(wind);
+
}
*/
if(key == 'g'){
@@ -546,9 +557,7 @@ void G308_keyboardListener(unsigned char key, int x, int y) {
bspline->readNewInterval();
glutPostRedisplay();
}
- //else if(key == 'c'){
- // bspline->printCoordinates();
- //}
+
//
// Move camera back to its original position.
else if (key == 'v') {
@@ -564,7 +573,8 @@ void G308_keyboardListener(unsigned char key, int x, int y) {
else if(key == '9'){
camera->zoom += 1;
}
- /*else if(key == '-' || key == '='){
+
+ else if(key == '-' || key == '='){
float XHI = 0.1f;
float XLO = -0.1f;
@@ -588,7 +598,18 @@ void G308_keyboardListener(unsigned char key, int x, int y) {
balls[currentBalls] = new Ball(p, v, special);
currentBalls ++;
printf("Good");
- }*/
+ }
+ else if(key == '1'){
+ lightsOn = !lightsOn;
+ if(lightsOn){
+ glEnable(GL_LIGHT0);
+ glEnable(GL_LIGHT1);
+ }
+ else{
+ glDisable(GL_LIGHT0);
+ glDisable(GL_LIGHT1);
+ }
+ }
}

0 comments on commit da311b0

Please sign in to comment.