switch to player bullet state

This commit is contained in:
gmueller 2011-02-08 23:06:43 +01:00
parent f93135b20f
commit d7abbcb5c7
4 changed files with 50 additions and 87 deletions

View File

@ -78,7 +78,7 @@ void Client::drawPlayer(player_t *player) {
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, player->team->color); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, player->team->color);
glMatrixMode( GL_MODELVIEW); glMatrixMode( GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
glTranslated(player->x, player->y, player->z); glMultMatrixf(player->m);
glEnableClientState( GL_VERTEX_ARRAY); glEnableClientState( GL_VERTEX_ARRAY);
glEnableClientState( GL_TEXTURE_COORD_ARRAY); glEnableClientState( GL_TEXTURE_COORD_ARRAY);
glEnableClientState( GL_NORMAL_ARRAY); glEnableClientState( GL_NORMAL_ARRAY);
@ -328,7 +328,7 @@ void Client::accelerate(double x, double y, double z) {
m << msg; m << msg;
network.send(m); network.send(m);
} }
#if 0
void Client::drop_bomb(double rx, double ry, double rz, double ttl) { void Client::drop_bomb(double rx, double ry, double rz, double ttl) {
bomb_drop_meesage_t msg; bomb_drop_meesage_t msg;
msg.x = game.local_player->x + rx * 20; msg.x = game.local_player->x + rx * 20;
@ -342,7 +342,7 @@ void Client::drop_bomb(double rx, double ry, double rz, double ttl) {
m << msg; m << msg;
network.send(m); network.send(m);
} }
#endif
void Client::loadConsoleFont() { void Client::loadConsoleFont() {
GLuint font_id = 0; GLuint font_id = 0;
@ -453,23 +453,25 @@ void Client::update() {
} else if (glfwGetKey('D')) { } else if (glfwGetKey('D')) {
accelerate(-rz * v, 0, rx * v); accelerate(-rz * v, 0, rx * v);
} }
#if 0
if (glfwGetKey(GLFW_KEY_SPACE)) { if (glfwGetKey(GLFW_KEY_SPACE)) {
accelerate(game.local_player->vx * -0.1, game.local_player->vy accelerate(game.local_player->vx * -0.1, game.local_player->vy
* -0.1, game.local_player->vz * -0.1); * -0.1, game.local_player->vz * -0.1);
} }
#endif
} }
#if 0
if (glfwGetKey(GLFW_KEY_LCTRL)) { if (glfwGetKey(GLFW_KEY_LCTRL)) {
if (time - last_bomb > 1.0) { if (time - last_bomb > 1.0) {
last_bomb = time; last_bomb = time;
drop_bomb(rx, ry, rz, 5.0); drop_bomb(rx, ry, rz, 5.0);
} }
} }
#endif
if (game.local_player) { if (game.local_player) {
camX = game.local_player->x; camX = game.local_player->m[12];
camY = game.local_player->y; camY = game.local_player->m[13];
camZ = game.local_player->z; camZ = game.local_player->m[14];
} else { } else {
camX = 1000.0; camX = 1000.0;
camY = 1000.0; camY = 1000.0;

View File

@ -36,18 +36,15 @@ void reset_team(Team *team) {
} }
void reset_player(player_t *player) { void reset_player(player_t *player) {
if (player->body.get() == 0)
return;
if (player->team) { if (player->team) {
player->x = player->team->x; player->body->getWorldTransform().setOrigin(btVector3(player->team->x,
player->y = player->team->y; player->team->y, player->team->z));
player->z = player->team->z;
} else { } else {
player->x = 0; player->body->getWorldTransform().setOrigin(btVector3(0, 0, 0));
player->y = 0;
player->z = 0;
} }
player->vx = 0.; player->body->setLinearVelocity(btVector3(0, 0, 0));
player->vy = 0.;
player->vz = 0.;
} }
void reset_point(point_t *point) { void reset_point(point_t *point) {
@ -76,12 +73,12 @@ void setup_player(player_t *player) {
player->id = 0; player->id = 0;
player->status = 0; player->status = 0;
player->team = NULL; player->team = NULL;
player->x = 0.0; // player->x = 0.0;
player->y = 0.0; // player->y = 0.0;
player->z = 0.0; // player->z = 0.0;
player->vx = 0.0; // player->vx = 0.0;
player->vy = 0.0; // player->vy = 0.0;
player->vz = 0.0; // player->vz = 0.0;
} }
void setup_point(point_t *point) { void setup_point(point_t *point) {
@ -224,25 +221,24 @@ player_t *Game::spawnPlayer(Team *team) {
player->team = team; player->team = team;
player->status = 1; player->status = 1;
player->id = max_player_id++; player->id = max_player_id++;
reset_player(player);
if (player->body.get() == 0) { if (player->body.get() == 0) {
std::cout << "[Game] create body" << std::endl; std::cout << "[Game] create body" << std::endl;
/// Create Dynamic Objects /// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(player->x, player->y, player->z));
btScalar mass(1.f); btScalar mass(1.f);
btVector3 localInertia(0, 0, 0); btVector3 localInertia(0, 0, 0);
shipShape->calculateLocalInertia(mass, localInertia); shipShape->calculateLocalInertia(mass, localInertia);
player->state.reset(new btDefaultMotionState()); player->state.reset(new btDefaultMotionState());
player->state->setWorldTransform(startTransform); player->state->setWorldTransform(btTransform::getIdentity());
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,
player->state.get(), shipShape.get(), localInertia); player->state.get(), shipShape.get(), localInertia);
player->body.reset(new btRigidBody(rbInfo)); player->body.reset(new btRigidBody(rbInfo));
player->body->setCcdSweptSphereRadius(1.5); player->body->setCcdSweptSphereRadius(1.5);
dynamicsWorld->addRigidBody(player->body.get()); dynamicsWorld->addRigidBody(player->body.get());
} }
reset_player(player);
return player; return player;
} }
@ -253,25 +249,24 @@ player_t *Game::spawnPlayerWithId(Team *team, uint16_t id) {
if (max_player_id < id) if (max_player_id < id)
max_player_id = id; max_player_id = id;
player->status = 1; player->status = 1;
reset_player(player);
if (player->body.get() == 0) { if (player->body.get() == 0) {
/// Create Dynamic Objects /// Create Dynamic Objects
std::cout << "[Game] create body" << std::endl; std::cout << "[Game] create body" << std::endl;
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(player->x, player->y, player->z));
btScalar mass(1.f); btScalar mass(1.f);
btVector3 localInertia(0, 0, 0); btVector3 localInertia(0, 0, 0);
shipShape->calculateLocalInertia(mass, localInertia); shipShape->calculateLocalInertia(mass, localInertia);
player->state.reset(new btDefaultMotionState()); player->state.reset(new btDefaultMotionState());
player->state->setWorldTransform(startTransform); player->state->setWorldTransform(btTransform::getIdentity());
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,
player->state.get(), shipShape.get(), localInertia); player->state.get(), shipShape.get(), localInertia);
player->body.reset(new btRigidBody(rbInfo)); player->body.reset(new btRigidBody(rbInfo));
player->body->setCcdSweptSphereRadius(1.5); player->body->setCcdSweptSphereRadius(1.5);
dynamicsWorld->addRigidBody(player->body.get()); dynamicsWorld->addRigidBody(player->body.get());
} }
reset_player(player);
return player; return player;
} }
@ -281,58 +276,22 @@ void Game::update_players(double dt) {
player_t *p = &player[i]; player_t *p = &player[i];
if (p->status == 0) if (p->status == 0)
return; return;
if (master || true) {
btTransform wt;
p->state->getWorldTransform(wt);
p->x = wt.getOrigin().x();
p->y = wt.getOrigin().y();
p->z = wt.getOrigin().z();
btVector3 v = p->body->getLinearVelocity();
p->vx = v.x();
p->vy = v.z();
p->vz = v.z();
} else {
std::cout << "update player " << p->id << ": " << p->x << " += "
<< p->vx << " * " << dt << std::endl;
p->x += p->vx * dt; btVector3 team_position(p->team->x, p->team->y, p->team->z);
p->y += p->vy * dt; btTransform player_transform;
p->z += p->vz * dt; p->state->getWorldTransform(player_transform);
} player_transform.getOpenGLMatrix(p->m);
double distance2 = pow(p->x - p->team->x, 2) double distance2 =
+ pow(p->y - p->team->y, 2) + pow(p->z - p->team->z, 2); player_transform.getOrigin().distance2(team_position);
if (distance2 < 10000) { if (distance2 < 10000) {
p->team->points += p->points; p->team->points += p->points;
p->points = 0; p->points = 0;
} }
// if (p->x < (-1000 + 10)) {
// p->x = (-1000 + 10);
// p->vx *= -1;
// } else if (p->x > (5000 - 10)) {
// p->x = (5000 - 10);
// p->vx *= -1;
// }
//
// if (p->y < (-3000 + 10)) {
// p->y = (-3000 + 10);
// p->vy *= -1;
// } else if (p->y > (3000 - 10)) {
// p->y = (3000 - 10);
// p->vy *= -1;
// }
//
// if (p->z < (-3000 + 10)) {
// p->z = (-3000 + 10);
// p->vz *= -1;
// } else if (p->z > (3000 - 10)) {
// p->z = (3000 - 10);
// p->vz *= -1;
// }
} }
} }
#if 0
void Game::explode_bomb(bomb_t *bomb) { void Game::explode_bomb(bomb_t *bomb) {
size_t i, j; size_t i, j;
for (i = 0; i < GAME_PLAYER_COUNT; i++) { for (i = 0; i < GAME_PLAYER_COUNT; i++) {
@ -430,6 +389,7 @@ void Game::update_points(double dt) {
update_point(p); update_point(p);
} }
} }
#endif
void Game::update(double time, double dt) { void Game::update(double time, double dt) {
if (master || true) { if (master || true) {
@ -437,13 +397,13 @@ void Game::update(double time, double dt) {
if (steps > 0) { if (steps > 0) {
double timeStep = dt; double timeStep = dt;
Game::update_players(timeStep); Game::update_players(timeStep);
Game::update_bombs(timeStep); //Game::update_bombs(timeStep);
Game::update_points(timeStep); //Game::update_points(timeStep);
} }
} else if (slaveUpdate.next(time)) { } else if (slaveUpdate.next(time)) {
Game::update_players(slaveUpdate.getInterval()); Game::update_players(slaveUpdate.getInterval());
Game::update_bombs(slaveUpdate.getInterval()); //Game::update_bombs(slaveUpdate.getInterval());
Game::update_points(slaveUpdate.getInterval()); //Game::update_points(slaveUpdate.getInterval());
} }
} }

View File

@ -31,13 +31,14 @@ class Game;
struct player_t { struct player_t {
uint16_t id; uint16_t id;
uint16_t status; uint16_t status;
double x, y, z; // double x, y, z;
double rx, ry, rz, rw; // double rx, ry, rz, rw;
double vx, vy, vz; // double vx, vy, vz;
Team *team; Team *team;
uint16_t points; uint16_t points;
std::auto_ptr<btMotionState> state; std::auto_ptr<btMotionState> state;
std::auto_ptr<btRigidBody> body; std::auto_ptr<btRigidBody> body;
float m[16];
}; };
struct bomb_t { struct bomb_t {

View File

@ -352,11 +352,11 @@ void Network::dispatch(enet_uint8 *data, size_t length) {
player_accelerate_message_t m; player_accelerate_message_t m;
doc >> m; doc >> m;
player_t *player = game->getPlayer(m.player_id); player_t *player = game->getPlayer(m.player_id);
player->vx += m.x; btVector3 v = player->body->getLinearVelocity();
player->vy += m.y; v += btVector3(m.x, m.y, m.z);
player->vz += m.z; player->body->setLinearVelocity(v);
player->body->activate(true); player->body->activate(true);
player->body->applyCentralImpulse(btVector3(m.x, m.y, m.z)); //player->body->applyCentralImpulse(btVector3(m.x, m.y, m.z));
break; break;
} }
case MESSAGE_BOMB_DROP: { case MESSAGE_BOMB_DROP: {