-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bullet, fix incorrect mouse coordinates when pointing into void
- Loading branch information
1 parent
d323968
commit cf003e1
Showing
11 changed files
with
206 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "physics.h" | ||
|
||
#include "Camera.h" | ||
|
||
PhysicsDebugDraw::PhysicsDebugDraw() : btIDebugDraw() { | ||
gl->glCreateBuffers(1, &vertex_buffer); | ||
shader = resource_manager.load<Shader>({ "Data/Shaders/physics_debug.vs", "Data/Shaders/physics_debug.fs" }); | ||
} | ||
|
||
void PhysicsDebugDraw::drawLine(const btVector3& from, const btVector3& to, const btVector3& color) { | ||
debug_vertices.push_back(from.x()); | ||
debug_vertices.push_back(from.y()); | ||
debug_vertices.push_back(from.z()); | ||
debug_vertices.push_back(to.x()); | ||
debug_vertices.push_back(to.y()); | ||
debug_vertices.push_back(to.z()); | ||
} | ||
|
||
void PhysicsDebugDraw::drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) { | ||
} | ||
|
||
void PhysicsDebugDraw::reportErrorWarning(const char* warningString) {} | ||
|
||
void PhysicsDebugDraw::draw3dText(const btVector3& location, const char* textString) { | ||
} | ||
|
||
void PhysicsDebugDraw::setDebugMode(int debugMode) {} | ||
|
||
int PhysicsDebugDraw::getDebugMode() const { | ||
return DBG_DrawWireframe; | ||
} | ||
|
||
void PhysicsDebugDraw::clearLines() { | ||
debug_vertices.clear(); | ||
} | ||
|
||
void PhysicsDebugDraw::render() { | ||
gl->glNamedBufferData(vertex_buffer, debug_vertices.size() * sizeof(float), debug_vertices.data(), GL_STATIC_DRAW); | ||
|
||
shader->use(); | ||
//gl->glDisable(GL_DEPTH_TEST); | ||
|
||
gl->glUniformMatrix4fv(1, 1, GL_FALSE, &camera->projection_view[0][0]); | ||
|
||
gl->glEnableVertexAttribArray(0); | ||
gl->glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); | ||
gl->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); | ||
|
||
gl->glDrawArrays(GL_LINES, 0, debug_vertices.size()); | ||
|
||
gl->glDisableVertexAttribArray(0); | ||
gl->glEnable(GL_DEPTH_TEST); | ||
} | ||
|
||
void Physics::initialize() { | ||
broadphase = new btDbvtBroadphase(); | ||
collisionConfiguration = new btDefaultCollisionConfiguration(); | ||
dispatcher = new btCollisionDispatcher(collisionConfiguration); | ||
solver = new btSequentialImpulseConstraintSolver; | ||
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); | ||
dynamicsWorld->setGravity(btVector3(0, 0, gravity)); | ||
|
||
draw = new PhysicsDebugDraw; | ||
draw->setDebugMode(draw->getDebugMode() | btIDebugDraw::DBG_DrawAabb); | ||
dynamicsWorld->setDebugDrawer(draw); | ||
} | ||
|
||
Physics physics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include "bullet/btBulletDynamicsCommon.h" | ||
#include <vector> | ||
#include "Shader.h" | ||
#include <memory> | ||
|
||
class PhysicsDebugDraw : public btIDebugDraw { | ||
std::shared_ptr<Shader> shader; | ||
GLuint vertex_buffer; | ||
|
||
|
||
public: | ||
std::vector<float> debug_vertices; | ||
PhysicsDebugDraw(); | ||
|
||
virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override; | ||
virtual void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) override; | ||
virtual void reportErrorWarning(const char* warningString) override; | ||
virtual void draw3dText(const btVector3& location, const char* textString) override; | ||
virtual void setDebugMode(int debugMode) override; | ||
virtual int getDebugMode() const override; | ||
virtual void clearLines() override; | ||
void render(); | ||
}; | ||
|
||
struct Physics { | ||
float gravity = -9.81f; | ||
|
||
btBroadphaseInterface* broadphase; | ||
btDefaultCollisionConfiguration* collisionConfiguration; | ||
btCollisionDispatcher* dispatcher; | ||
btSequentialImpulseConstraintSolver* solver; | ||
btDiscreteDynamicsWorld* dynamicsWorld; | ||
|
||
|
||
PhysicsDebugDraw* draw; | ||
|
||
|
||
void initialize(); | ||
|
||
~Physics() { | ||
delete dynamicsWorld; | ||
delete solver; | ||
delete collisionConfiguration; | ||
delete dispatcher; | ||
delete broadphase; | ||
} | ||
}; | ||
|
||
extern Physics physics; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#version 450 core | ||
|
||
out vec4 color; | ||
|
||
void main() { | ||
color = vec4(0, 1, 0, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#version 450 core | ||
|
||
layout (location = 0) in vec3 vPosition; | ||
layout (location = 1) uniform mat4 MVP; | ||
|
||
void main() { | ||
gl_Position = MVP * vec4(vPosition, 1); | ||
} |
Oops, something went wrong.