Permalink
Browse files

Meged

  • Loading branch information...
2 parents f732f93 + 1d58cb6 commit b2eaccbc333125ca31e8225a46d7ca9d11a8ec3d @bettsmatt committed Oct 16, 2012
Showing with 22,425 additions and 160 deletions.
  1. +4 −0 .gitignore
  2. BIN .nfs0000000000dee14800000080
  3. +1 −0 BSpline.cpp
  4. +3 −1 Ball.cpp
  5. +5 −1 Camera.cpp
  6. +1 −1 Camera.h
  7. +92 −39 Collision.cpp
  8. +0 −10 ControlPoint.cpp
  9. +0 −1 ControlPoint.h
  10. +1 −1 FileReader.cpp
  11. +85 −53 G308_Geometry.cpp
  12. +4 −4 G308_Geometry.h
  13. +14 −16 GJK.cpp
  14. +3 −2 GJK.h
  15. +1 −1 Makefile
  16. +23 −20 ParticleEmitter.cpp
  17. +1,967 −0 Sphere.obj
  18. +33 −0 cube.obj
  19. +58 −10 main.cpp
  20. +338 −0 priman.asf
  21. +15,002 −0 pumpkin.obj
  22. +4,790 −0 teddy.obj
View
@@ -10,3 +10,7 @@
*.lai
*.la
*.a
+
+.nfs*
+
+BetaFX
Binary file not shown.
View
@@ -108,6 +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);
if(infoDisplay) controlPoints[i].showTime();
}
View
@@ -35,6 +35,9 @@ Ball::Ball(float* initialPosition, float* initialVelocity, bool sp) {
for(int i = 0 ; i < 3 ; i ++)
position[i] = initialPosition[i];
+ for(int i = 0 ; i < 3 ; i ++)
+ acceletation[i] = 0;
+
mass = 1; // Default
}
@@ -76,7 +79,6 @@ void Ball::tick (){
velocity[i] += acceletation[i];
position[i] += velocity[i];
acceletation[i] = 0;
-
if(velocity[i] > 5) velocity[i] = 5;
}
}
View
@@ -16,7 +16,11 @@
Camera::Camera() {
- zoom, rotx, roty, tx, ty = 0.0f;
+ zoom = 0.0f;
+ rotx = 0.0f;
+ roty = 0.0f;
+ tx = 0.0f;
+ ty = 0.0f;
ref = new RefFrame();
count = 0;
}
View
@@ -28,7 +28,7 @@ class Camera {
public:
float zoom, rotx, roty, tx, ty;
- //float posX, posY, posZ;
+ float posX, posY, posZ;
Camera();
virtual ~Camera();
View
@@ -8,17 +8,18 @@
#include "Collision.h"
#include "math.h"
#include "stdio.h"
+#include "G308_Geometry.h"
Collision::Collision() {}
Collision::~Collision() {}
bool Collision::checkIfCollidedBalls(Ball* b1, Ball* b2){
- return (calculateVectorDistance(b1->position, b2->position) < 2);
+ return (calculateVectorDistance(b1->position, b2->position) < (b1->mass + b2->mass));
}
bool Collision::checkIfCollidedBallParticle(Ball* b, Particle* p){
- return (calculateVectorDistance(b->position, p->position) < 1.1);
+ return (calculateVectorDistance(b->position, p->position) < b->mass + 0.1f);
}
float Collision::calculateVectorDistance(float *v1, float* v2)
@@ -61,9 +62,6 @@ void Collision::collisionBall(double cor, double mass1, double mass2, double rad
float sp = sin(phi2);
float cp = cos(phi2);
- // printf("st: %f\n", st);
- // printf("ct: %f\n", ct);
-
// Express the velocity vector of ball 1 in a rotated coordinate
// System where ball 2 lies on the z-axis
float vx1r = ct * cp * vel1[0] + ct * sp * vel1[1] - st * vel1[2];
@@ -111,34 +109,15 @@ void Collision::collisionBall(double cor, double mass1, double mass2, double rad
}
void Collision::collisionPlane(double cor, float* ballVel, float* planeNormal){
- //Project the spheres velocity on the planes normal
- // a . b
- // ----- * b
- // |a|
- float velocityMag = vectorMagnitude(ballVel);
- float dotProduct = vectorDotProduct(ballVel, planeNormal);
- float projectionLength = dotProduct / velocityMag;
-
- float projectionVector[3] = {
- planeNormal[0] * projectionLength,
- planeNormal[1] * projectionLength,
- planeNormal[2] * projectionLength
- };
-
- //multiply the projection by 2
- cor += 1;
- projectionVector[0] *= cor;
- projectionVector[1] *= cor;
- projectionVector[2] *= cor;
-
- //subtract it from the spheres velocity
- float finalVelocity[3] = {
- ballVel[0] - projectionVector[0],
- ballVel[1] - projectionVector[1],
- ballVel[2] - projectionVector[2]
+ float dotprod = -2 * (ballVel[0] * planeNormal[0] + ballVel[1] * planeNormal[1] + ballVel[2] * planeNormal[2]);
+ float nextVector[3] = {
+ cor * (planeNormal[0] * dotprod + ballVel[0]),
+ cor * (planeNormal[1] * dotprod + ballVel[1]),
+ cor * (planeNormal[2] * dotprod + ballVel[2])
};
-
- ballVel = finalVelocity;
+ ballVel[0] = nextVector[0];
+ ballVel[1] = nextVector[1];
+ ballVel[2] = nextVector[2];
}
void Collision::checkCollision(double cor, Cube *c, Ball *b)
@@ -156,21 +135,95 @@ void Collision::checkCollision(double cor, Cube *c, Ball *b)
if((b->position[0] > (c->position[0] + c->width/2) && b->velocity[0] < 0) ||
(b->position[0] < (c->position[0] - c->width/2) && b->velocity[0] > 0)){
//Collision in x direction
- b->position[0] -= b->velocity[0]; //Move back
- b->velocity[0] = -b->velocity[0]*cor; //Invert velocity
+ //b->position[0] -= b->velocity[0]; //Move back
+ //b->velocity[0] = -b->velocity[0]*cor; //Invert velocity
+ b->position[1] -= b->velocity[1]; //Move back
+ b->position[0] -= b->velocity[0];
+ b->position[2] -= b->velocity[2];
+ float n[3] = {1, 0, 0};
+ collisionPlane(cor, b->velocity, n);
}
else if((b->position[1] > (c->position[1] + c->height/2) && b->velocity[1] < 0) ||
(b->position[1] < (c->position[1] - c->height/2) && b->velocity[1] > 0)){
- //float n[3] = {0, 1, 0};
- //collisionPlane(1, b->velocity, n);
+ //printf("ballVel before: %f %f %f\n", b->velocity[0], b->velocity[1], b->velocity[2]);
//Collision in z direction
b->position[1] -= b->velocity[1]; //Move back
- b->velocity[1] = -b->velocity[1]*cor; //Invert velocity
+ b->position[0] -= b->velocity[0];
+ b->position[2] -= b->velocity[2];
+ float n[3] = {0, 1, 0};
+ collisionPlane(cor, b->velocity, n);
+ //b->velocity[1] = -b->velocity[1]*cor; //Invert velocity
}
else if((b->position[2] > (c->position[2] + c->height/2) && b->velocity[2] < 0) ||
(b->position[2] < (c->position[2] - c->height/2) && b->velocity[2] > 0)){
- b->position[2] -= b->velocity[2]; //Move back
- b->velocity[2] = -b->velocity[2]*cor; //Invert velocity
+ //b->position[2] -= b->velocity[2]; //Move back
+ //b->velocity[2] = -b->velocity[2]*cor; //Invert velocity
+ b->position[1] -= b->velocity[1]; //Move back
+ b->position[0] -= b->velocity[0];
+ b->position[2] -= b->velocity[2];
+ float n[3] = {0, 0, 1};
+ collisionPlane(cor, b->velocity, n);
}
}
+
+
+
+
+
+
+ // 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];
+ sphereCenterRelBox[1] = b->position[1] - c->position[1];
+ sphereCenterRelBox[2] = b->position[2] - c->position[2];
+
+ // Point on surface of box that is closest to the center of the sphere
+ float* boxPoint = new float[3];
+
+ // Check sphere center against box along the X axis alone.
+ // If the sphere is off past the left edge of the box,
+ // then the left edge is closest to the sphere.
+ // Similar if it's past the right edge. If it's between
+ // the left and right edges, then the sphere's own X
+ // is closest, because that makes the X distance 0,
+ // and you can't get much closer than that :)
+ if (sphereCenterRelBox[0] < c->width/2.0)
+ boxPoint[0] = -c->width/2.0;
+ else if (sphereCenterRelBox[0] > c->width/2.0)
+ boxPoint[0] = c->width/2.0;
+ else
+ boxPoint[0] = sphereCenterRelBox[0];
+
+ // ...same for Y axis
+ if (sphereCenterRelBox[1] < -c->width/2.0)
+ boxPoint[1] = -c->width/2.0;
+ else if (sphereCenterRelBox[1] > c->width/2.0)
+ boxPoint[1] = c->width/2.0;
+ else
+ boxPoint[1] = sphereCenterRelBox[1];
+
+ // ... same for Z axis
+ if (sphereCenterRelBox[2] < -c->width/2.0)
+ boxPoint[2] = -c->width/2.0;
+ else if (sphereCenterRelBox[2] > c->width/2.0)
+ boxPoint[2] = c->width/2.0;
+ else
+ boxPoint[2] = sphereCenterRelBox[2];
+
+ // Now we have the closest point on the box, so get the distance from
+ // that to the sphere center, and see if it's less than the radius
+ float* dist = new float[3];//Sphere.center - Box.center;
+ dist[0] = sphereCenterRelBox[0] - boxPoint[0];
+ 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)
+ printf("True\n");
}
+
+/*void Collision::checkCollision(double cor, G308_Geometry *g, Ball *b)
+{
+ //x2 + y2 + z2 = r2;
+ G308_Point* points = new G308_Point[6];
+
+}*/
View
@@ -100,16 +100,6 @@ ControlPoint operator-(const ControlPoint& p1, const ControlPoint& p2) {
return q;
}
-ControlPoint operator*(const ControlPoint& q1, const ControlPoint& q2) {
-// float a = q1.a * q2.a - q1.b * q2.b - q1.c * q2.c - q1.d * q2.d;
-// float b = q1.a * q2.b + q1.b * q2.a + q1.c * q2.d - q1.d * q2.c;
-// float c = q1.a * q2.c - q1.b * q2.d + q1.c * q2.a + q1.d * q2.b;
-// float d = q1.a * q2.d + q1.b * q2.c - q1.c * q2.b + q1.d * q2.a;
-//
-// ControlPoint q(a, b, c, d);
-// return q;
-}
-
ControlPoint operator*(const ControlPoint& p1, const float& f) {
ControlPoint q(f * p1.x, f * p1.y, f * p1.z);
return q;
View
@@ -30,7 +30,6 @@ class ControlPoint {
friend ControlPoint operator+(const ControlPoint&, const ControlPoint&);
friend ControlPoint operator-(const ControlPoint&, const ControlPoint&);
-friend ControlPoint operator*(const ControlPoint&, const ControlPoint&);
friend ControlPoint operator*(const ControlPoint&, const float&);
friend ControlPoint operator/(const ControlPoint&, const float&);
View
@@ -360,7 +360,7 @@ void FileReader::readBone(char* buff, FILE* file) {
} else {
sscanf(p, "%s ", t1);
if (strcmp(t1, "id") == 0) {
- sscanf(p, "id %s", id);
+ sscanf(p, "id %i", &id);
root[numBones].id = id;
}
else if (strcmp(t1, "name") == 0) {
Oops, something went wrong.

0 comments on commit b2eaccb

Please sign in to comment.