Skip to content

Commit

Permalink
Game objects sizeable
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Reineke committed Dec 26, 2010
1 parent fe334a1 commit a8b4791
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
33 changes: 14 additions & 19 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rendering/sphere_shape.h"
#include "control.h"
#include "main.h"
#include "units.h"

extern "C" {
#include <stdlib.h>
Expand All @@ -33,7 +34,6 @@ extern "C" {

using namespace std;


void init_sdl(SDL_Surface **screen, int bpp, int flags, int width, int height);
void init_scene(gl_renderer *renderer);

Expand Down Expand Up @@ -68,34 +68,31 @@ int main(int argc, char **argv)
renderer->stop();
}


void init_scene(gl_renderer *renderer)
{
/* ----- Init scene --------------- */

world = new simulation_world();
game_object::set_simulation_world(world);
for(int i=0; i<10;i++){
game_object* sun = new game_object();
rigid_body * r = world->add_body(100.0f);
sun->set_rigid_body(r);
float rx = -50.0 + (rand() % 100);
float ry = -50.0 + (rand() % 100);
//float rz = -50.0 + (rand() % 100);
sun->set_position( rx, ry, 0.0f);
game_objects.push_front(sun);

renderer->add_star(sun);
//GravityController * sungrav = new GravityController(sun, &game_objects);
//game_controllers.push_front(sungrav);
}
game_object* sun = new game_object();
rigid_body * r = world->add_body(100.0f);
sun->set_rigid_body(r);
//float rz = -50.0 + (rand() % 100);
sun->set_position(0.0f, 0.0f, 0.0f);
game_objects.push_front(sun);

renderer->add_star(sun);
//GravityController * sungrav = new GravityController(sun, &game_objects);
//game_controllers.push_front(sungrav);

ship1 = new game_object();
rigid_body * r = world->add_body( 1.0f );
r = world->add_body( 1.0f );
ship1->set_rigid_body(r);
ship1->set_position(1.0f, 1.0f, 0.0f);
game_objects.push_front(ship1);


printf("Foo\n");

GravityController * gravcontrol1 = new GravityController(ship1, &game_objects);
control1 = new SpaceShipController(ship1);
Expand All @@ -113,5 +110,3 @@ void init_scene(gl_renderer *renderer)
game_controllers.push_front(control2);
}



1 change: 0 additions & 1 deletion rendering/ego_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ego_camera::ego_camera(game_object *go, float x, float y, float z)

void ego_camera::apply_rotation()
{
//glRotatef(180.0f, 0.0, 1.0f, 0.0f);
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glRotatef(-go->orientation(), 0.0f,0.0f,1.0f);
}
Expand Down
6 changes: 3 additions & 3 deletions rendering/gl_drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void gl_drawable::draw()
{
glPushMatrix();
glTranslatef(-go->posx(),-go->posy(),-go->posz());
glRotatef(go->orientation(), 0.0f,0.0f,1.0f);
glRotatef(90,1.0f,0.0f,0.0f);
glScalef(0.2f, 0.2f, 0.2f);
glRotated(go->orientation(), 0.0,0.0,1.0);
glRotated(90,1.0,0.0,0.0);
glScaled(0.2, 0.2, 0.2);
sh->draw();
glPopMatrix();
}
Expand Down
10 changes: 6 additions & 4 deletions rendering/gl_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "sphere_shape.h"
#include "../control.h"
#include "../main.h"
#include "../units.h"

extern "C" {
#include <stdlib.h>
Expand All @@ -28,14 +29,16 @@ extern "C" {
#include "../physics.h"
}

#define SHIPSCALE 0.1

gl_renderer::gl_renderer() {
drawables = new list<gl_drawable*>();
}

void gl_renderer::add_ship(game_object *go, int cam)
{
drawables->push_front(new gl_drawable(go, ship_shape));
game_camera[cam] = new ego_camera(go, 0.0f, -0.4f, -0.15f);
game_camera[cam] = new ego_camera(go, 0.0f, -0.4f * SHIPSCALE, -0.15f * SHIPSCALE);

}

Expand Down Expand Up @@ -126,9 +129,8 @@ void gl_renderer::init()
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);

ship_shape = new obj_shape(new string("ptr_mk1.obj"));
star_shape = new sphere_shape(5.0f);

ship_shape = new obj_shape(new string("ptr_mk1.obj"), SHIPSCALE);
star_shape = new sphere_shape(1392000.0 * KM);
background_stars = new skybox();
background_stars->init(200.0f);

Expand Down
7 changes: 5 additions & 2 deletions rendering/obj_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ obj_shape::~obj_shape()
free(Faces);
}

obj_shape::obj_shape(string *name)
obj_shape::obj_shape(string *name, double scale)
{
char *cname = (char*) malloc(200);
strcpy (cname, name->c_str());
Expand All @@ -26,6 +26,7 @@ obj_shape::obj_shape(string *name)
printf("Cannot load the object!\n");
}
set_object(object);
this->scale = scale;
}


Expand All @@ -44,7 +45,8 @@ void obj_shape::draw()
int nf, i;
Face *face;
Point *n, *t, *v;


glScaled(scale, scale, scale);
glBindTexture(GL_TEXTURE_2D, TexId);
glBegin(GL_TRIANGLES);
for(nf=0; nf < nFaces; nf++) {
Expand All @@ -59,5 +61,6 @@ void obj_shape::draw()
glVertex3f(v->x, v->y, v->z);
}
}
glScaled(1.0/scale, 1.0/scale, 1.0/scale);
glEnd();
}
6 changes: 3 additions & 3 deletions rendering/obj_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ class obj_shape : public shape
{
public:
~obj_shape();
obj_shape(string *name);
obj_shape(string *name, double scale);
virtual void draw();
void set_object(Object *object);

void set_object(Object *object);
private:
Object *object;
GLuint TexId;
Expand All @@ -20,4 +19,5 @@ class obj_shape : public shape
Point *Vertices; /* Array of vertex coordinates */
Point *TexCoords; /* Array of texture coordinates */
Point *Normals; /* Array of normal vectors */
double scale;
};

0 comments on commit a8b4791

Please sign in to comment.