From f5266b403c50cb2b6d712e6d8f41b62ad2433efb Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 1 May 2008 12:41:31 +0000 Subject: lights --- osirion.kdevelop | 2 +- osirion.kdevelop.pcs | Bin 561248 -> 579707 bytes osirion.kdevses | 15 ++++++-- src/client/camera.cc | 4 +- src/client/camera.h | 3 ++ src/client/view.cc | 2 +- src/core/entity.cc | 14 ++++++- src/core/gameserver.cc | 6 ++- src/core/netclient.cc | 5 +-- src/core/netserver.cc | 2 +- src/game/ship.cc | 8 ++-- src/math/axis.cc | 10 ++++- src/math/axis.h | 3 ++ src/render/draw.cc | 100 ++++++++++++++++++++++++++++++------------------- src/render/draw.h | 2 +- src/render/render.cc | 5 +++ 16 files changed, 123 insertions(+), 58 deletions(-) diff --git a/osirion.kdevelop b/osirion.kdevelop index 475045a..58a8bfc 100644 --- a/osirion.kdevelop +++ b/osirion.kdevelop @@ -21,7 +21,7 @@ - src/math/libmath.la + src/client/libclient.la debug diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs index b532052..ded2355 100644 Binary files a/osirion.kdevelop.pcs and b/osirion.kdevelop.pcs differ diff --git a/osirion.kdevses b/osirion.kdevses index 8674cfa..a1c17a4 100644 --- a/osirion.kdevses +++ b/osirion.kdevses @@ -1,10 +1,19 @@ - - - + + + + + + + + + + + + diff --git a/src/client/camera.cc b/src/client/camera.cc index d264ddf..e2dbacf 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -25,6 +25,7 @@ namespace camera // gameworld coordinates of the camera target math::Vector3f target; math::Vector3f eye; +math::Axis axis; // target yaw, angle in XZ plane, positive is looking left float yaw_target; @@ -130,7 +131,6 @@ void next_mode() void draw(float elapsed) { math::Matrix4f matrix; - math::Axis axis; float d = 0; @@ -158,7 +158,7 @@ void draw(float elapsed) if (mode == Track) { // make the camera swing while turning - yaw_target = 25 * core::localcontrol()->target_direction; + yaw_target = -25.0f * core::localcontrol()->target_direction; pitch_target = pitch_track - 25 * core::localcontrol()->target_pitch; } diff --git a/src/client/camera.h b/src/client/camera.h index 2a79fda..25e179d 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -47,6 +47,9 @@ namespace camera /// gameworld coordinates of the camera eye extern math::Vector3f eye; + /// global camera axis coordinate system + extern math::Axis axis; + /// current camera mode extern Mode mode; diff --git a/src/client/view.cc b/src/client/view.cc index 39cd351..6f5ceca 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -268,7 +268,7 @@ void frame(float seconds) camera::draw(seconds); // draw the current camera transformation - render::draw(camera::eye, camera::target, seconds); // draw the world + render::draw(camera::axis, camera::eye, camera::target, seconds); // draw the world } diff --git a/src/core/entity.cc b/src/core/entity.cc index 475af39..b186c64 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -231,13 +231,19 @@ void EntityDynamic::recieve_client_update(std::istream &is) void EntityDynamic::serialize_server_update(std::ostream & os) const { - os << entity_location << " " << entity_axis << " " << entity_speed; + os << entity_location << " "; + os << entity_axis.forward() << " "; + os << entity_axis.left() << " "; + os << entity_axis.up() << " "; + os << entity_speed; } void EntityDynamic::recieve_server_update(std::istream &is) { is >> entity_location; - is >> entity_axis; + is >> entity_axis[0]; + is >> entity_axis[1]; + is >> entity_axis[2]; is >> entity_speed; } @@ -253,6 +259,7 @@ EntityControlable::EntityControlable(Player *player, unsigned int flags) : target_direction = 0.0f; target_thrust = 0.0f; + target_pitch = 0.0f; } EntityControlable::EntityControlable(std::istream & is) : @@ -285,13 +292,16 @@ void EntityControlable::serialize_client_update(std::ostream & os) const { EntityDynamic::serialize_client_update(os); os << " " << target_direction; + os << " " << target_pitch; os << " " << target_thrust; + } void EntityControlable::recieve_client_update(std::istream &is) { EntityDynamic::recieve_client_update(is); is >> target_direction; + is >> target_pitch; is >> target_thrust; } diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 1aa57f0..2169e21 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -143,7 +143,7 @@ void GameServer::say(Player *player, std::string const &message) con_print <name() << ": " << message << "\n"; // broadcast to remote clients - if (server_network != 0 ) { + if (server_network) { std::string netmessage("msg public "); netmessage.append(player->name()); netmessage.append(": "); @@ -286,12 +286,14 @@ void GameServer::frame(float seconds) if (entity->entity_destroyed) { if (!entity->entity_created) { std::ostringstream netmsg; + netmsg.str(""); netmsg << "die " << entity->id() << "\n"; server_network->broadcast(netmsg.str()); } core::Entity::remove(entity->id()); } else if (entity->entity_created) { std::ostringstream netmsg; + netmsg.str(""); netmsg << "ent "; entity->serialize(netmsg); netmsg << "\n"; @@ -300,9 +302,11 @@ void GameServer::frame(float seconds) } else if (entity->dirty()) { std::ostringstream netmsg; + netmsg.str(""); netmsg << "sup " << entity->id() << " "; entity->serialize_server_update(netmsg); netmsg << "\n"; + netmsg.flush(); server_network->broadcast(netmsg.str()); } entity->entity_dirty = false; diff --git a/src/core/netclient.cc b/src/core/netclient.cc index c910e26..0c0d72a 100644 --- a/src/core/netclient.cc +++ b/src/core/netclient.cc @@ -121,7 +121,6 @@ void NetClient::send(std::string const &msg) void NetClient::transmit(int serverfd) { - if (!sendq.size()) { if (client_keepalive + NETTIMEOUT/2 < application()->time()) { sendq.assign("ping\n"); @@ -129,7 +128,7 @@ void NetClient::transmit(int serverfd) return; } } else if (sendq.size() >= FRAMESIZE) { - con_warn << "Outgoing message exceeds " << FRAMESIZE << " bytes!\n"; + con_warn << "Outgoing message exceeds " << FRAMESIZE -1 << " bytes!\n"; //sendq.clear(); //return; } @@ -137,7 +136,7 @@ void NetClient::transmit(int serverfd) ssize_t bytes_sent = 0; while (sendq.size() && !error()) { - bytes_sent = ::sendto(serverfd, sendq.c_str(), sendq.size(), 0, + bytes_sent = ::sendto(serverfd, sendq.c_str(), sendq.size()+1, 0, (struct sockaddr *)&client_addr, sizeof(client_addr)); if (bytes_sent < 0) { diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 8b9cbe5..064229b 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -178,7 +178,7 @@ void NetServer::receive() timeval timeout; timeout.tv_sec = 0; - timeout.tv_usec = 0; + timeout.tv_usec = 25000; fd_set readset = serverset; int nb = select(fd()+1, &readset, NULL, NULL, &timeout); diff --git a/src/game/ship.cc b/src/game/ship.cc index c9e2266..538a1e6 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -48,9 +48,9 @@ void Ship::frame(float seconds) else if (target_pitch < -1.0f) target_pitch = -1.0f; - float pitch_offset = ship_shipmodel->turnspeed() * seconds * target_pitch; + float pitch_offset = seconds * target_pitch; if (pitch_offset) - entity_axis.change_pitch(360.0f * pitch_offset); + entity_axis.change_pitch(360.0f * ship_shipmodel->turnspeed() * pitch_offset); // update direction if (target_direction > 1.0f) @@ -58,9 +58,9 @@ void Ship::frame(float seconds) else if (target_direction < -1.0f) target_direction = -1.0f; - float direction_offset = ship_shipmodel->turnspeed() * seconds * target_direction; + float direction_offset = seconds * target_direction; if (direction_offset) - entity_axis.change_direction(360.0f * direction_offset); + entity_axis.change_direction(360.0f * ship_shipmodel->turnspeed() * direction_offset); // update speed if (entity_speed < entity_thrust * ship_shipmodel->maxspeed()) { diff --git a/src/math/axis.cc b/src/math/axis.cc index 6f9710b..4d752bf 100644 --- a/src/math/axis.cc +++ b/src/math/axis.cc @@ -89,7 +89,9 @@ Axis const Axis::transpose() // write an axis to a std::ostream std::ostream &operator<<(std::ostream & os, Axis const & axis) { - os << axis.forward() << " " << axis.left() << " " << axis.up(); + os << axis.forward() << " "; + os << axis.left() << " "; + os << axis.up(); return os; } @@ -102,4 +104,10 @@ std::istream &operator>>(std::istream & is, Axis & axis) return is; } +// local-to-global coordinates +Vector3f operator*(Axis const &axis, Vector3f const &vector) +{ + return (Vector3f(vector[0] * axis[0] + vector[1] * axis[1] + vector[2] * axis[2])); +} + } diff --git a/src/math/axis.h b/src/math/axis.h index 7e81d9a..d011675 100644 --- a/src/math/axis.h +++ b/src/math/axis.h @@ -58,6 +58,9 @@ std::ostream &operator<<(std::ostream & os, Axis const & axis); /// read an axis from a std::istream std::istream &operator>>(std::istream & is, Axis & axis); +/// local-to-global coordinates +Vector3f operator*(Axis const &axis, Vector3f const &vector); + } #endif // __INCLUDED_MATH_AXIS_H__ diff --git a/src/render/draw.cc b/src/render/draw.cc index 4b42596..5697cae 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -36,6 +36,7 @@ const float drawfxdistance = 32.0f; math::Vector3f camera_target; math::Vector3f camera_eye; +math::Axis camera_axis; float angle = 0; @@ -181,27 +182,6 @@ void draw_model_evertex(core::Entity *entity) } } -void draw_model_lights(core::Entity *entity) -{ - core::Model *model = entity->model(); - - if (model->model_light.size()) { - glPointSize(10); - gl::begin(gl::Points); - - for (std::list::iterator lit = model->model_light.begin(); lit != model->model_light.end(); lit++) { - if (!(*lit)->strobe() || (( core::application()->time() - floorf(core::application()->time()) ) < 0.5f)) { - math::Vector3f location = (*lit)->location(); - gl::color((*lit)->color()); - gl::vertex(location); - } - } - - gl::end(); - glPointSize(1); - } -} - void draw_model_engines(core::EntityControlable *entity) { core::Model *model = entity->model(); @@ -364,7 +344,7 @@ void draw_pass_model_evertex() } } -/* Draw model lights, engines */ +/* Draw model shields and engines */ void draw_pass_model_fx() { for (std::map::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { @@ -373,23 +353,68 @@ void draw_pass_model_fx() { if (test_drawfx_distance(entity)) { - gl::push(); - gl::translate(entity->location()); - // FIXME - //gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); - gl::multmatrix(entity->axis()); - - draw_model_lights(entity); - + if (entity->type() == core::Entity::Controlable) { + gl::push(); + gl::translate(entity->location()); + gl::multmatrix(entity->axis()); + draw_model_engines((core::EntityControlable *)entity); draw_model_shield((core::EntityControlable *)entity); + gl::pop(); } - gl::pop(); + } } } +/* draw model lights */ + +void draw_pass_model_lights() +{ + //glPointSize(10); + glBindTexture(GL_TEXTURE_2D, render::textures[3]); // bitmaps/fx/flare01.tga + gl::enable(GL_TEXTURE_2D); + + gl::begin(gl::Quads); + + const float light_size = 0.0625; + + for (std::map::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { + core::Entity *entity = (*it).second; + + if ( test_drawfx_distance(entity) && (entity->model()->model_light.size())) { + + for (std::list::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) { + if (!(*lit)->strobe() || (( core::application()->time() - floorf(core::application()->time()) ) < 0.5f)) { + math::Vector3f location = entity->location() + (entity->axis() * (*lit)->location()); + float n = dotproduct(camera_axis.forward(), (camera_eye-location)); + + if (n < 0) { + math::Color color((*lit)->color()); + color.a = fabs(-atanf(n) * 2 / M_PI); + gl::color(color); + + glTexCoord2f(0,1); + gl::vertex(location + (camera_axis.up() - camera_axis.left()) * light_size); + glTexCoord2f(0,0); + gl::vertex(location + (camera_axis.up() + camera_axis.left()) * light_size); + glTexCoord2f(-1,0); + gl::vertex(location + (camera_axis.up() * -1 + camera_axis.left()) * light_size); + glTexCoord2f(-1,1); + gl::vertex(location + (camera_axis.up() * -1 - camera_axis.left()) * light_size); + } + } + } + } + } + + gl::end(); + gl::disable(GL_TEXTURE_2D); + //glPointSize(1); + +} + void draw_pass_model_radius() { if (!(r_radius && r_radius->value())) @@ -485,7 +510,7 @@ void draw_local_axis() } /* ----- Main draw routine ----------------------------------------- */ -void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds) +void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f const &target, float seconds) { Stats::clear(); @@ -497,6 +522,7 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds camera_target.assign(target); camera_eye.assign(eye); + camera_axis.assign(axis); gl::enable(GL_DEPTH_TEST); // enable depth buffer writing gl::enable(GL_CULL_FACE); // enable culling @@ -533,7 +559,10 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds gl::disable(GL_LIGHTING); gl::enable(GL_BLEND); - draw_pass_model_fx(); // draw entity lights and engines + draw_pass_spacegrid(); // draw the blue spacegrid + + draw_pass_model_fx(); // draw entity shield and engines + draw_pass_model_lights(); // draw entity lights gl::enable(GL_LIGHTING); gl::enable(GL_RESCALE_NORMAL); @@ -547,11 +576,6 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds gl::disable(GL_LIGHTING); gl::disable(GL_COLOR_MATERIAL); // disable color tracking gl::disable(GL_CULL_FACE); // disable culling - - // draw_local_axis(); - - draw_pass_spacegrid(); // draw the blue spacegrid - gl::disable(GL_DEPTH_TEST); // disable depth buffer // GL_BLEND must be enabled for the GUI diff --git a/src/render/draw.h b/src/render/draw.h index b423aad..65e15ee 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -13,7 +13,7 @@ namespace render { /// draw the world -void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds); +void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f const &target, float seconds); class Stats { public: diff --git a/src/render/render.cc b/src/render/render.cc index 7f79a85..6755e08 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -75,6 +75,11 @@ void init() core::application()->shutdown(); } + if (!texture("bitmaps/fx/flare01.tga", 3)) { + con_error << "Essential file bitmaps/fx/flare01.tga missing" << std::endl; + core::application()->shutdown(); + } + // size of the vertex array in megabytes r_arraysize = core::Cvar::get("r_arraysize", 0.0f , core::Cvar::Archive); r_arraysize->set_info("[int] size of the vertex array in Mb"); -- cgit v1.2.3