couch/core/World.h

81 lines
2.0 KiB
C
Raw Permalink Normal View History

2021-04-21 15:06:03 -05:00
/**
@file
@author Dane Johnson <dane@danejohnson.org>
@section LICENSE
Couch Copyright (C) 2021 Dane Johnson
This program comes with ABSOLUTELY NO WARRANTY; without event the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for details at
https://www.gnu.org/licenses/gpl-3.0.html
This is free software, and you are welcome to redistribute it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
@section DESCRIPTION
The physics world
*/
2021-01-24 22:55:36 -06:00
#ifndef WORLD_H
#define WORLD_H
#include <btBulletDynamicsCommon.h>
#include "Rigidbody.h"
2021-04-21 21:30:48 -05:00
/**
Holds information about the results of a raycast
*/
2021-04-21 18:27:30 -05:00
struct RaycastResult {
bool hit;
Vector3 position;
Vector3 normal;
Rigidbody *object;
};
2021-04-21 15:06:03 -05:00
/**
World is the object that performs the rigidbody physics simulation. Presently there is only one world.
*/
2021-01-24 22:55:36 -06:00
class World {
public:
2021-04-21 15:06:03 -05:00
/**
@returns the World singleton
*/
2021-01-24 22:55:36 -06:00
static World* GetWorld();
2021-04-21 15:06:03 -05:00
/**
Add a rigidbody to the physics simulation
@param rigidbody the rigidbody to add
*/
2021-01-24 22:55:36 -06:00
void AddRigidbody(Rigidbody *rigidbody);
2021-04-21 15:06:03 -05:00
/**
Advance the physics simulation
@param delta the time that has passed since the last physics update
*/
void Step(float delta);
2021-04-21 18:27:30 -05:00
2021-04-21 21:30:48 -05:00
/**
Performs a raycast
@param from the start location of the raycast
@param to the end location of the raycast
@returns a RaycastResult with data collected by the raycast
*/
2021-04-21 18:27:30 -05:00
RaycastResult Raycast(const Vector3 &from, const Vector3 &to);
2021-01-24 22:55:36 -06:00
private:
static World* world;
2021-04-21 18:27:30 -05:00
// Some hocus pocus
2021-01-24 22:55:36 -06:00
btDiscreteDynamicsWorld *btWorld;
btDefaultCollisionConfiguration *collisionConfiguration;
btCollisionDispatcher *dispatcher;
btBroadphaseInterface *overlappingPairCache;
btSequentialImpulseConstraintSolver *solver;
World();
~World();
2021-04-21 18:27:30 -05:00
2021-01-24 22:55:36 -06:00
};
#endif /* WORLD_H */