From 98691940165bc2681fb99784afb9b12b7604b43f Mon Sep 17 00:00:00 2001 From: Philip Hazelden Date: Wed, 9 Feb 2011 16:52:36 +0000 Subject: [PATCH] Draw bullets, but not oriented or scaled correctly. --- src/bullet.cpp | 23 +++++++++++++++++++++++ src/bullet.h | 6 ++++++ src/globals.cpp | 2 ++ src/globals.h | 1 + src/world.cpp | 5 +++++ 5 files changed, 37 insertions(+) diff --git a/src/bullet.cpp b/src/bullet.cpp index 8f96f42..c43a8c6 100644 --- a/src/bullet.cpp +++ b/src/bullet.cpp @@ -1,4 +1,5 @@ #include "bullet.h" +#include "globals.h" Bullet::Bullet(ph::vec3f pos, ph::vec3f vel) { shape = new btSphereShape(0.2); @@ -9,6 +10,13 @@ Bullet::Bullet(ph::vec3f pos, ph::vec3f vel) { initialize(mass, inertia, state); + sprite.SetImage(G::images::bullet_red); + + localVertices[0] = Vertex(ph::vec3f(-1, 0, 1), 0, 1); + localVertices[1] = Vertex(ph::vec3f(1, 0, 1), 1, 1); + localVertices[2] = Vertex(ph::vec3f(1, 0, -1), 1, 0); + localVertices[3] = Vertex(ph::vec3f(-1, 0, -1), 0, 0); + body->setGravity(btVector3(0,0,0)); // If we move further than this in a given timestep, use continuous @@ -37,7 +45,22 @@ void Bullet::update() { ph::vec3f pos = trans.getOrigin(); } +void Bullet::draw() { + printf("ohai\n"); + + sprite.GetImage()->Bind(); + + glPushMatrix(); + + btTransform trans; + body->getMotionState()->getWorldTransform(trans); + ph::vec3f pos = trans.getOrigin(); + glTranslatef(pos.x, pos.z, pos.y); + localVertices[0].draw(GL_QUADS, 4); + + glPopMatrix(); +} diff --git a/src/bullet.h b/src/bullet.h index bf94f21..fec0ffc 100644 --- a/src/bullet.h +++ b/src/bullet.h @@ -2,6 +2,7 @@ #define GOE_BULLET_H #include "entity.h" +#include "vertex.h" class Bullet : public Entity { public: @@ -9,7 +10,12 @@ class Bullet : public Entity { Bullet(ph::vec3f pos, ph::vec3f vel); + sf::Sprite sprite; + + Vertex localVertices[4]; + void update(); + void draw(); }; #endif diff --git a/src/globals.cpp b/src/globals.cpp index 741ac95..b9b2665 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -26,9 +26,11 @@ btCollisionShape* G::shapes::ground = new btStaticPlaneShape(btVector3(0, 0, 1), 0); sf::Image G::images::wall; +sf::Image G::images::bullet_red; void G::loadImages() { images::wall.LoadFromFile("media/wall.tga"); + images::bullet_red.LoadFromFile("media/jelly-bullet-red.tga"); } sf::Vector2i G::getMouseMoveDelta(sf::Event e) { diff --git a/src/globals.h b/src/globals.h index 571c55a..3a53aa1 100644 --- a/src/globals.h +++ b/src/globals.h @@ -39,6 +39,7 @@ class G { struct images { static sf::Image wall; + static sf::Image bullet_red; }; static void loadImages(); diff --git a/src/world.cpp b/src/world.cpp index 287ef85..10097b9 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -88,6 +88,11 @@ void World::draw() { w->draw(); } + foreach (Entity *e, entities) { + if (e) + e->draw(); + } + if (G::debugMode) { GLCheck( glBindTexture(GL_TEXTURE_2D, 0) ); GLCheck( glDepthFunc(GL_ALWAYS) );