Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Particles with trails

  • Loading branch information...
commit 55cc08bfc2e1e536d9f6ca3ef7f98acf2c2b515b 2 parents c115732 + da311b0
@bettsmatt authored
View
14 .cproject
@@ -38,7 +38,6 @@
<tool id="cdt.managedbuild.tool.gnu.assembler.base.2060099739" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1582393259" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
-
</toolChain>
</folderInfo>
</configuration>
@@ -52,4 +51,17 @@
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</storageModule>
+ <storageModule moduleId="refreshScope"/>
+ <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
+ <buildTargets>
+ <target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
+ <buildCommand>make</buildCommand>
+ <buildArguments/>
+ <buildTarget>clean</buildTarget>
+ <stopOnError>true</stopOnError>
+ <useDefaultCommand>true</useDefaultCommand>
+ <runAllBuilders>true</runAllBuilders>
+ </target>
+ </buildTargets>
+ </storageModule>
</cproject>
View
13 BSpline.cpp
@@ -39,7 +39,7 @@ BSpline::~BSpline() {
}
void BSpline::init(){
- n = 3; // Degree of the curve
+ n = 3; // Degree of the curtestve
pointSelected = -1;
frames = NULL;
deltaTime = 0.01f;
@@ -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,7 +272,7 @@ 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];
@@ -281,13 +280,13 @@ void BSpline::selectPoint(int x, int y){
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
2  BSpline.h
@@ -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
7 Ball.cpp
@@ -29,14 +29,11 @@ Ball::Ball(float* initialPosition, float* initialVelocity, bool sp) {
isSpecial = sp;
// Set initial velocity
- for(int i = 0 ; i < 3 ; i ++)
+ for(int i = 0 ; i < 3 ; i ++){
velocity[i] = initialVelocity[i];
-
- for(int i = 0 ; i < 3 ; i ++)
position[i] = initialPosition[i];
-
- for(int i = 0 ; i < 3 ; i ++)
acceletation[i] = 0;
+ }
mass = 1; // Default
View
7 Camera.cpp
@@ -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
20 Collision.cpp
@@ -170,7 +170,7 @@ void Collision::checkCollision(double cor, Cube *c, Ball *b)
-
+ /*
// Get the center of the sphere relative to the center of the box
float* sphereCenterRelBox = new float[3];//Sphere.center - Box.center;
sphereCenterRelBox[0] = b->position[0] - c->position[0];
@@ -217,8 +217,24 @@ void Collision::checkCollision(double cor, Cube *c, Ball *b)
dist[1] = sphereCenterRelBox[1] - boxPoint[1];
dist[2] = sphereCenterRelBox[2] - boxPoint[2];
- if (dist[0]*dist[0] + dist[1]*dist[1] + dist[2]*dist[2] < b->mass*b->mass)
+ if (dist[0]*dist[0] + dist[1]*dist[1] + dist[2]*dist[2] < b->mass*b->mass){
printf("True\n");
+
+ float* test = new float[3];
+ test[1] = b->position[1] - b->velocity[1]; //Move back
+ test[0] = b->position[0] - b->velocity[0];
+ test[2] = b->position[2] - b->velocity[2];
+
+
+
+
+
+ }
+
+
+ delete[] sphereCenterRelBox;
+ delete[] boxPoint;
+ delete[] dist;*/
}
/*void Collision::checkCollision(double cor, G308_Geometry *g, Ball *b)
View
2  ControlPoint.cpp
@@ -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
4 ControlPoint.h
@@ -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
2  GJK.cpp
@@ -42,6 +42,7 @@ bool GJK::shapesIntersect(G308_Point* shape1, G308_Point* shape2, int shape1Coun
G308_Point A = maxPointInMinkDiffAlongDir(shape1, shape2, D);
if (pointDotProduct(A, D) < 0)
{
+ //printf("Miss\n");
return false;
}
@@ -50,6 +51,7 @@ bool GJK::shapesIntersect(G308_Point* shape1, G308_Point* shape2, int shape1Coun
if (updateSimplexAndDirection(simplex, D))
{
+ //printf("Hit\n");
return true;
}
}
View
2  Makefile
@@ -1,7 +1,7 @@
CC = g++
LPATH = -L/usr/pkg/lib
LDPATH = -Wl,-R/usr/pkg/lib
-CFLAGS=-g -Wall
+CFLAGS=-g -Wall -Wextra -pedantic
LIBS=-lGL -lglut -lGLU -ljpeg -lpng15 -lm
IPATH= -I/usr/pkg/include
View
103 Particle.cpp
@@ -32,8 +32,6 @@ Particle::Particle(float* pos, float* initialVelocity, float m, G308_Point* cam,
acceletation[i] = 0;
position[i] = 0;
velocity[i] = 0;
-
- ;
position[i] = pos[i];
velocity[i] = initialVelocity[i];
}
@@ -53,6 +51,7 @@ Particle::Particle(float* pos, float* initialVelocity, float m, G308_Point* cam,
trail = (float**) malloc(sizeof(float*) * TRAILMAX);
+
for (int i = 0 ; i < TRAILMAX ; i ++){
trail[i] = new float[3];
trail[i][0] = pos[0];
@@ -60,12 +59,21 @@ Particle::Particle(float* pos, float* initialVelocity, float m, G308_Point* cam,
trail[i][2] = pos[2];
}
- trailIndex = 0;
+}
+Particle::~Particle(){
+ //delete position;
+ //delete velocity;
+ //delete acceletation;
-}
+ /*
+ for (int i = 0 ; i < TRAILMAX ; i ++){
+ free(trail[i]);
+ }*/
+ //free(trail);
+}
bool Particle::isDead(){
// Particle's timer has run down
@@ -97,13 +105,16 @@ void Particle::tick (){
lifeSpanLeft--;
}
- trail[trailIndex][0] = position[0];
- trail[trailIndex][1] = position[1];
- trail[trailIndex][2] = position[2];
+ for(int i = TRAILMAX - 1 ; i > 0 ; i --){
+ trail[i][0] = trail[i - 1][0];
+ trail[i][1] = trail[i - 1][1];
+ trail[i][2] = trail[i - 1][2];
+ }
+
+ trail[0][0] = position[0];
+ trail[0][1] = position[1];
+ trail[0][2] = position[2];
- trailIndex ++;
- if(trailIndex == TRAILMAX)
- trailIndex = 0;
}
/*
@@ -126,12 +137,33 @@ void Particle::renderParticle() {
glPushMatrix();
- // Fade color from red to blue over time
- glColor3f(
- (float)lifeSpanLeft / (float)lifeSpan,
- 0,
- 1 - ((float)lifeSpanLeft / (float)lifeSpan)
- );
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_POINT_SPRITE_ARB);
+
+ glBindTexture(GL_TEXTURE_2D, 1);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+
+// SUN
+ if(!dies){
+ glColor3f(
+ 0,
+ 1,
+ 0
+ );
+ } // Fade color from red to blue over time
+ else{
+ glColor3f(
+ (float)lifeSpanLeft / (float)lifeSpan,
+ 0,
+ 1 - ((float)lifeSpanLeft / (float)lifeSpan)
+ );
+ }
// Translate to where the particle is
glTranslatef(
@@ -162,8 +194,10 @@ void Particle::renderParticle() {
glLoadMatrixf(modelview);
+ float size = 0.3f;
- float size = 0.1f;
+ if(!dies)
+ size = 1;
// Draw Quad
glBegin(GL_QUADS);
@@ -181,28 +215,30 @@ void Particle::renderParticle() {
glEnd();
+ glPopMatrix();
+ glDisable(GL_BLEND);
+ glDisable(GL_POINT_SPRITE_ARB);
+ glDisable(GL_TEXTURE_2D);
+ glPushMatrix();
+ glBegin(GL_LINE);
+ for(int i = 0 ; i < TRAILMAX - 1 ; i ++){
- glPopMatrix();
-
- glPushMatrix();
- glBegin(GL_LINE_STRIP);
- for(int i = 0 ; i < TRAILMAX ; i ++){
glVertex3f(
trail[i][0],
trail[i][1],
trail[i][2]
);
-
- printf("Trail %f %f %f \n",
- trail[i][0],
- trail[i][1],
- trail[i][2]
+ glVertex3f(
+ trail[i + 1][0],
+ trail[i + 1][1],
+ trail[i + 1][2]
);
+
}
glEnd();
glPopMatrix();
@@ -219,7 +255,7 @@ void Particle::applyFriction(float friction){
for(int i = 0 ; i < 3 ; i++)
f[i] = velocity[i] * -friction;
applyForce(f);
- free(f);
+ delete[] f;
}
void Particle::applyAttractiveForce(Particle* p1, Particle* p2, float strength, float minDist){
@@ -227,15 +263,13 @@ void Particle::applyAttractiveForce(Particle* p1, Particle* p2, float strength,
float* vec = (float*) malloc (sizeof(float) * 3);
// Vector between particles
- for(int i = 0 ; i < 3 ; i ++)
+ for(int i = 0 ; i < 3 ; i ++){
+ vec[i] = 0;
vec[i] = p2->position[i] - p1->position[i];
+ }
// Distance
- float dist = sqrt(
- vec[0] * vec[0] +
- vec[1] * vec[1] +
- vec[2] * vec[2]
- );
+ float dist = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
// Close enough
if(dist < minDist){
@@ -259,6 +293,7 @@ void Particle::applyAttractiveForce(Particle* p1, Particle* p2, float strength,
// Apply to p2
p2->applyForce(vecN);
*/
+ delete[] vecN;
}
free(vec);
View
2  Particle.h
@@ -34,13 +34,13 @@ class Particle
bool dies;
float** trail;
- int trailIndex;
public:
Particle(float*, float*, float, G308_Point*, bool);
+ ~Particle();
int lifeSpanLeft;
float* position; // x, y, z
float* velocity; // x, y, z
View
28 ParticleEmitter.cpp
@@ -171,6 +171,7 @@ void ParticleEmitter::cloud(int num, float radius){
v[j] = 0;
p[j] = 0 + sin((float)rand()/((float)RAND_MAX/(PI*2-0))) * (float)rand()/((float)RAND_MAX/(radius-0));
}
+
create(p,v,1.0f);
}
@@ -182,7 +183,7 @@ void ParticleEmitter::create(float* p, float * v, float m){
if(index >= MAX_PARTICLES)
index = 0;
- delete particles[index];
+ //delete particles[index];
particles[index] = new Particle(p,v, 1, camera,true);
@@ -269,7 +270,7 @@ void ParticleEmitter::tick(){
// Alive!
if(!particles[i]->isDead()){
- particles[i]->applyFriction(0.01f);
+ particles[i]->applyFriction(0.0001f);
if(gravityOn)
for(int j = 0 ; j < numGravity ; j ++)
@@ -385,6 +386,9 @@ void ParticleEmitter::renderParticles() {
pq.push(*particles[i]);
}
}
+ for(int i = 0; i < numGravity ; i ++)
+ pq.push(*gravity[i]);
+
// Rotate to face vector, might take this out
@@ -396,29 +400,18 @@ void ParticleEmitter::renderParticles() {
);
glutWireCone(1,1,3,3);
-
+ glDepthMask(0);
glPopMatrix();
glPushMatrix();
/*
* All particles have the same texture, so we do this here.
*/
- glEnable(GL_TEXTURE_2D);
- //glDepthMask(0);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_POINT_SPRITE_ARB);
-
- glBindTexture(GL_TEXTURE_2D, 1);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
+ /*
for(int i = 0; i < numGravity ; i ++)
gravity[i]->renderParticle();
-
+*/
int size = pq.size();
for(int i = 0 ; i < size ; i ++){
Particle p = pq.top();
@@ -438,7 +431,7 @@ void ParticleEmitter::renderParticles() {
glDisable(GL_BLEND);
glDisable(GL_POINT_SPRITE_ARB);
glDisable(GL_TEXTURE_2D);
- //glDepthMask(1);
+ glDepthMask(1);
@@ -466,5 +459,4 @@ void ParticleEmitter::collideWithBalls(Ball* ball, Collision* c){
}
}
}
-
}
View
16 Skeleton.cpp
@@ -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,8 +135,11 @@ 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();
@@ -142,6 +147,7 @@ void Skeleton::move(BSpline* bs){
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,7 +226,7 @@ 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 };
@@ -228,10 +234,10 @@ void Skeleton::drawOnePart(bone* root, GLUquadric* q) {
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
139,960 bunny.obj
139,960 additions, 0 deletions not shown
View
85 main.cpp
@@ -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;
@@ -63,6 +64,7 @@ float camAngle;
float camHeight;
int animate = 0;
int maxBalls;
+int currentBalls;
/*
* Particle Emitter
@@ -124,7 +126,7 @@ int main(int argc, char** argv) {
createCubes();
geometry = new G308_Geometry();
- geometry->ReadOBJ("teddy.obj");
+ geometry->ReadOBJ("cube.obj");
geometry->CreateGLPolyGeometry();
geometry->CreateGLWireGeometry();
@@ -189,6 +191,7 @@ void loadTexture (char* filename, GLuint id){
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, t->width, t->height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, t->textureData);
+ free(t);
}
/*
@@ -202,22 +205,21 @@ void tick (){
* Simulate a frame in the particle emitter
*/
particeEmitter->tick();
- //particeEmitter->emit();
- for(int i = 0; i < maxBalls; i ++){
+ for(int i = 0; i < currentBalls; i ++){
balls[i]->tick();
}
- for(int i = 0; i < maxBalls; i++){
- for(int j = i+1; j < maxBalls; j++){
+ for(int i = 0; i < currentBalls; i++){
+ for(int j = i+1; j < currentBalls; j++){
if(i != j && c->checkIfCollidedBalls(balls[i], balls[j])){
c->collisionBall(1, balls[i]->mass, balls[j]->mass, 2, 2, balls[i]->position, balls[j]->position, balls[i]->velocity, balls[j]->velocity);
}
}
}
- for(int i = 0; i < maxBalls; i++){
+ for(int i = 0; i < currentBalls; i++){
particeEmitter->collideWithBalls(balls[i], c);
}
- for(int i = 0; i < maxBalls; i++){
+ for(int i = 0; i < currentBalls; i++){
for(int j = 0; j < 5; j++){
c->checkCollision(1.0, cubes[j], balls[i]);
}
@@ -226,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);
@@ -237,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;
}
@@ -261,7 +268,10 @@ void tick (){
secondPoint[i].z = second->m_pVertexArray[i].z;
}
- //gjk->shapesIntersect(geometryPoint, secondPoint, geometry->m_nNumPoint, second->m_nNumPoint);
+ gjk->shapesIntersect(geometryPoint, secondPoint, geometry->m_nNumPoint, second->m_nNumPoint);
+ delete gjk;
+ delete geometryPoint;
+ delete secondPoint;
}
@@ -305,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){
@@ -329,12 +339,12 @@ void G308_display() {
/*
* Draw the particle emmiter and it's particles
*/
- for(int i = 0; i < maxBalls; i ++) balls[i]->renderBall();
+ for(int i = 0; i < currentBalls; i ++) balls[i]->renderBall();
glPushMatrix();
glColor3f(0.0f, 0.5f, 0.5f);
glTranslatef(test, 0.0f, 0.0f);
- glScalef(0.1f, 0.1f, 0.1f);
- //geometry->RenderGeometry();
+ glRotatef(45, 0, 0, 1);
+ geometry->RenderGeometry();
glPopMatrix();
glPushMatrix();
@@ -405,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){
@@ -423,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:
@@ -439,8 +455,6 @@ void menu(int item) {
break;
}
- printf("Choice changed\n");
-
glutPostRedisplay();
}
@@ -489,6 +503,7 @@ void G308_keyboardListener(unsigned char key, int x, int y) {
wind[0] = 0.1f;
particeEmitter->applyWind(wind);
+
}
*/
if(key == 'g'){
@@ -542,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') {
@@ -561,6 +574,42 @@ void G308_keyboardListener(unsigned char key, int x, int y) {
camera->zoom += 1;
}
+ else if(key == '-' || key == '='){
+ float XHI = 0.1f;
+ float XLO = -0.1f;
+
+ float YHI = 0.1f;
+ float YLO = -0.1f;
+
+ float ZHI = 0.3f;
+ float ZLO = 0.2f;
+
+ float* v = new float[3];
+ v[0] = XLO + (float)rand()/((float)RAND_MAX/(XHI-XLO));
+ v[1] = YLO + (float)rand()/((float)RAND_MAX/(YHI-YLO));
+ v[2] = ZLO + (float)rand()/((float)RAND_MAX/(ZHI-ZLO));
+
+ if(currentBalls == maxBalls) return;
+ //float v[3] = {0.00f, 0.00f, 0.0f};
+ float p[3] = {0.0f, 6.0f, 0.0f};
+ bool special = true;
+ if(key == '-') special = false;
+
+ 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);
+ }
+ }
}
@@ -650,6 +699,8 @@ void createBalls(){
balls[i] = new Ball(p, v, true);
}
}
+ maxBalls = 20;
+ currentBalls = 5;
}
void createCubes(){
Please sign in to comment.
Something went wrong with that request. Please try again.