hey, Im back, Ive got a more in depth question for you now. Ive managed to combine glut and box2d but collision detection isint really working, i was wondering how you would suggest I went about it.
here is my code:
Code:
#include <stdlib.h>
#include <stdio.h>
#include<GL/glut.h>
#include "Box2D.h"
float angle = 0.0;
///box2d
b2World* myWorld;
b2Body* body;
void changeSize(int w, int h) {
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
float ratio = 1.0* w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,
0.0,0.0,-1.0,
0.0f,1.0f,0.0f);
}
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glRotatef(angle,0.0f,1.0f,0.0f);
//draw here
float32 timeStep = 1.0f / 60.0f;
int32 iterations = 10;
myWorld->Step(timeStep, iterations);
b2Vec2 position = body->GetPosition();
float32 angle = body->GetAngle();
printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_POINTS);
glVertex2f(position.x/10,position.y/10);
glEnd();
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < 4; ++i)
{
//glVertex2f( ->vertices[i].x, ->vertices[i].y);
glVertex2f((float)i/1,(float)i/1);
}
glEnd();
//end draw
glPopMatrix();
glutSwapBuffers();
//printf("%f\n", angle);
}
void main(int argc, char **argv)
{
//box2d
b2AABB worldAABB;
worldAABB.lowerBound.Set(-100.0f, -100.0f);
worldAABB.upperBound.Set(100.0f, 100.0f);
b2Vec2 gravity(0.0f, -10.0f);
bool doSleep = true;
myWorld = new b2World(worldAABB, gravity, doSleep);
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0.0f, -10.0f);
b2Body* groundBody = myWorld->CreateBody(&groundBodyDef);
b2PolygonDef groundShapeDef;
groundShapeDef.SetAsBox(50.0f, 10.0f);
groundShapeDef.isSensor = true;
groundShapeDef.filter.groupIndex = 1;
b2BodyDef bodyDef;
bodyDef.position.Set(0.0f, 4.0f);
body = myWorld->CreateBody(&bodyDef);
b2PolygonDef shapeDef;
shapeDef.SetAsBox(1.0f, 1.0f);
shapeDef.density = 1.0f;
shapeDef.friction = 0.3f;
shapeDef.isSensor = true;
shapeDef.filter.groupIndex = 1;
body->CreateShape(&shapeDef);
body->SetMassFromShapes();
//glut
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
glutInitWindowPosition(1000,1000);
glutInitWindowSize(800,500);
glutCreateWindow("ShockAndAwe");
glutFullScreen();
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutReshapeFunc(changeSize);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}