Skip to content

Commit

Permalink
Draw bullets, but not oriented or scaled correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChickenProp committed Feb 9, 2011
1 parent 1cb509b commit 9869194
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 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);
Expand All @@ -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
Expand Down Expand Up @@ -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();
}



Expand Down
6 changes: 6 additions & 0 deletions src/bullet.h
Expand Up @@ -2,14 +2,20 @@
#define GOE_BULLET_H

#include "entity.h"
#include "vertex.h"

class Bullet : public Entity {
public:
typedef Entity super;

Bullet(ph::vec3f pos, ph::vec3f vel);

sf::Sprite sprite;

Vertex localVertices[4];

void update();
void draw();
};

#endif
2 changes: 2 additions & 0 deletions src/globals.cpp
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/globals.h
Expand Up @@ -39,6 +39,7 @@ class G {

struct images {
static sf::Image wall;
static sf::Image bullet_red;
};
static void loadImages();

Expand Down
5 changes: 5 additions & 0 deletions src/world.cpp
Expand Up @@ -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) );
Expand Down

0 comments on commit 9869194

Please sign in to comment.