forked from StaticHex/cs354r_p2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhysics.h
79 lines (69 loc) · 2.69 KB
/
Physics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#ifndef __Physics_h_
#define __Physics_h_
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h>
#include <vector>
#include <map>
#include "Sphere.h"
#include "Room.h"
#include "Block.h"
#include "Paddle.h"
#include <SDL.h>
#include <SDL_mixer.h>
#define MAX_BLOCKS 999
class Physics
{
public:
// Public Members
std::map<void*, int> userIndex; // Map holds the index of all objects
std::vector<btRigidBody*> ballRigidBody; // Holds the pointer to the physics objects for ball
std::vector<btRigidBody*> blockRigidBody; // Holds the pointer to the physics objects for block
btRigidBody* paddleRigidBody1;// Holds the pointer to the hit area for the paddle1
btRigidBody* paddleRigidBody2;// Holds the pointer to the hit area for the paddle2
// Constructor and deconstructor declared here
Physics(std::vector<Sphere*>balls, std::vector<Block*> blocks, Room* &space, Paddle* &pad1, Paddle* &pad2, bool multi);
~Physics();
int checkCollide(Paddle* &pad1, Paddle* &pad2, std::vector<Block*> &blk); // Check for collisions between specific objects
void update(double tStep, double rate); // Update the simulation (simulation step)
void updatePaddle(Paddle* &pad); // Update position of the paddle's hit area to match the paddle graphic
// Sounds
Mix_Chunk* bounce;
bool soundOn = true;
bool multiplayer;
private:
// Basic Physics Variables
btBroadphaseInterface* broadphase;
btDefaultCollisionConfiguration* collisionConfiguration;
btCollisionDispatcher* dispatcher;
btSequentialImpulseConstraintSolver* solver;
btDiscreteDynamicsWorld* dynamicsWorld;
// Dynamic Objects (blocks, balls, powerups, etc.)
std::vector<btCollisionShape*> ballShape; // mass = 1
std::vector<btCollisionShape*> blockShape; // mass = 0
btCollisionShape* paddleShape; // mass = 0;
// Static Objects (walls, ceiling, floor)
btCollisionShape* groundShape;
std::vector<btCollisionShape*> wallShape;
btCollisionShape* ceilShape;
// Motion states for objects
std::vector<btDefaultMotionState*> ballMotionState;
std::vector<btDefaultMotionState*> blockMotionState;
btDefaultMotionState* groundMotionState;
std::vector<btDefaultMotionState*> wallMotionState;
btDefaultMotionState* ceilMotionState;
btDefaultMotionState* paddleMotionState1;
btDefaultMotionState* paddleMotionState2;
// Rigid bodies (the physical objects that interact with each other in the world)
btRigidBody* groundRigidBody;
std::vector<btRigidBody*> wallRigidBody;
btRigidBody* ceilRigidBody;
// SetUp Dynamic Objects
btScalar ballMass;
btScalar blockMass;
btScalar paddleMass;
btVector3 ballInertia;
btVector3 blockInertia;
btVector3 paddleInertia;
};
#endif // #ifndef __Physics_h_