1) The physics are now using the actual dimension of the track when
creating the world (which might give a performance boost). 2) Moved ssg_help into utils directory, added a namespace, and changed parameters to use Vec3 (instead of 3 floats). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2279 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
c0226902a7
commit
32df4eb50b
@ -51,6 +51,7 @@ supertuxkart_SOURCES = main.cpp \
|
||||
audio/sfx_openal.cpp audio/sfx_openal.hpp \
|
||||
audio/sound_manager.cpp audio/sound_manager.hpp \
|
||||
utils/random_generator.hpp utils/random_generator.cpp \
|
||||
utils/ssg_help.cpp tuils/ssg_help.hpp \
|
||||
material_manager.cpp material_manager.hpp \
|
||||
grand_prix_manager.cpp grand_prix_manager.hpp \
|
||||
attachment.cpp attachment.hpp \
|
||||
@ -91,7 +92,6 @@ supertuxkart_SOURCES = main.cpp \
|
||||
camera.cpp camera.hpp \
|
||||
sdldrv.cpp sdldrv.hpp \
|
||||
moveable.cpp moveable.hpp \
|
||||
ssg_help.cpp ssg_help.hpp \
|
||||
kart.cpp kart.hpp \
|
||||
auto_kart.hpp \
|
||||
player_kart.cpp player_kart.hpp \
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "projectile_manager.hpp"
|
||||
#include "callback_manager.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "ssg_help.hpp"
|
||||
#include "utils/ssg_help.hpp"
|
||||
|
||||
// static variables:
|
||||
float Flyable::m_st_speed[COLLECT_MAX];
|
||||
@ -108,9 +108,10 @@ void Flyable::init(const lisp::Lisp* lisp, ssgEntity *model,
|
||||
lisp->get("force-updown", m_st_force_updown[type]);
|
||||
|
||||
// Store the size of the model
|
||||
float x_min, x_max, y_min, y_max, z_min, z_max;
|
||||
MinMax(model, &x_min, &x_max, &y_min, &y_max, &z_min, &z_max);
|
||||
m_st_extend[type] = btVector3(x_max-x_min,y_max-y_min, z_max-z_min);
|
||||
Vec3 min, max;
|
||||
|
||||
SSGHelp::MinMax(model, &min, &max);
|
||||
m_st_extend[type] = btVector3(max-min);
|
||||
m_st_model[type] = model;
|
||||
} // init
|
||||
|
||||
|
@ -851,10 +851,6 @@
|
||||
RelativePath="..\..\smoke.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="../../../src\ssg_help.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="../../../src\static_ssg.cpp"
|
||||
>
|
||||
@ -1110,6 +1106,10 @@
|
||||
RelativePath="..\..\utils\random_generator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\utils\ssg_help.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="audio"
|
||||
@ -1668,6 +1668,10 @@
|
||||
RelativePath="..\..\utils\random_generator.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\utils\ssg_help.hpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="audio"
|
||||
|
18
src/kart.cpp
18
src/kart.cpp
@ -39,19 +39,19 @@
|
||||
#include "track.hpp"
|
||||
#include "world.hpp"
|
||||
#include "kart.hpp"
|
||||
#include "ssg_help.hpp"
|
||||
#include "physics.hpp"
|
||||
#include "kart_properties_manager.hpp"
|
||||
#include "gui/menu_manager.hpp"
|
||||
#include "gui/race_gui.hpp"
|
||||
#include "translation.hpp"
|
||||
#include "smoke.hpp"
|
||||
#include "material_manager.hpp"
|
||||
#include "kart_properties_manager.hpp"
|
||||
#include "gui/menu_manager.hpp"
|
||||
#include "gui/race_gui.hpp"
|
||||
#include "audio/sound_manager.hpp"
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "audio/sfx_base.hpp"
|
||||
#include "network/race_state.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
#include "utils/ssg_help.hpp"
|
||||
|
||||
|
||||
Kart::Kart (const std::string& kart_name, int position,
|
||||
@ -1053,19 +1053,19 @@ void Kart::load_wheels(ssgBranch* branch)
|
||||
{ // We found something that might be a wheel
|
||||
if (strcmp(i->getName(), "WheelFront.L") == 0)
|
||||
{
|
||||
m_wheel_front_l = add_transform(dynamic_cast<ssgTransform*>(i));
|
||||
m_wheel_front_l = SSGHelp::add_transform(dynamic_cast<ssgTransform*>(i));
|
||||
}
|
||||
else if (strcmp(i->getName(), "WheelFront.R") == 0)
|
||||
{
|
||||
m_wheel_front_r = add_transform(dynamic_cast<ssgTransform*>(i));
|
||||
m_wheel_front_r = SSGHelp::add_transform(dynamic_cast<ssgTransform*>(i));
|
||||
}
|
||||
else if (strcmp(i->getName(), "WheelRear.L") == 0)
|
||||
{
|
||||
m_wheel_rear_l = add_transform(dynamic_cast<ssgTransform*>(i));
|
||||
m_wheel_rear_l = SSGHelp::add_transform(dynamic_cast<ssgTransform*>(i));
|
||||
}
|
||||
else if (strcmp(i->getName(), "WheelRear.R") == 0)
|
||||
{
|
||||
m_wheel_rear_r = add_transform(dynamic_cast<ssgTransform*>(i));
|
||||
m_wheel_rear_r = SSGHelp::add_transform(dynamic_cast<ssgTransform*>(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1109,7 +1109,7 @@ void Kart::loadData()
|
||||
// else needed to load the wheels as a separate object.
|
||||
ssgFlatten(obj);
|
||||
|
||||
createDisplayLists(obj); // create all display lists
|
||||
SSGHelp::createDisplayLists(obj); // create all display lists
|
||||
ssgRangeSelector *lod = new ssgRangeSelector ;
|
||||
|
||||
lod -> addKid ( obj ) ;
|
||||
|
@ -17,20 +17,21 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "kart_properties.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <plib/ssg.h>
|
||||
#include "material_manager.hpp"
|
||||
#include "lisp/parser.hpp"
|
||||
#include "lisp/lisp.hpp"
|
||||
#include "loader.hpp"
|
||||
#include "file_manager.hpp"
|
||||
#include "string_utils.hpp"
|
||||
#include "kart_properties.hpp"
|
||||
#include "stk_config.hpp"
|
||||
#include "translation.hpp"
|
||||
#include "ssg_help.hpp"
|
||||
#include "user_config.hpp"
|
||||
#include "lisp/parser.hpp"
|
||||
#include "lisp/lisp.hpp"
|
||||
#include "utils/ssg_help.hpp"
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
# define snprintf _snprintf
|
||||
@ -103,11 +104,11 @@ void KartProperties::load(const std::string filename, const std::string node,
|
||||
return;
|
||||
}
|
||||
ssgStripify(m_model);
|
||||
float x_min, x_max, y_min, y_max, z_min, z_max;
|
||||
MinMax(m_model, &x_min, &x_max, &y_min, &y_max, &z_min, &z_max);
|
||||
m_kart_width = x_max - x_min;
|
||||
m_kart_length = y_max - y_min;
|
||||
m_kart_height = z_max - z_min;
|
||||
Vec3 min, max;
|
||||
SSGHelp::MinMax(m_model, &min, &max);
|
||||
m_kart_width = max.getX()-min.getY();
|
||||
m_kart_length = max.getY()-min.getY();
|
||||
m_kart_height = max.getZ()-min.getZ();
|
||||
|
||||
// Useful when tweaking kart parameters
|
||||
if(user_config->m_print_kart_sizes)
|
||||
|
@ -17,15 +17,17 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "moving_physics.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#define _WINSOCKAPI_
|
||||
#include <plib/sg.h>
|
||||
#include "moving_physics.hpp"
|
||||
|
||||
#include "string_utils.hpp"
|
||||
#include "world.hpp"
|
||||
#include "ssg_help.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "utils/ssg_help.hpp"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
MovingPhysics::MovingPhysics(const std::string data)
|
||||
@ -152,25 +154,28 @@ void MovingPhysics::init()
|
||||
|
||||
// 3. Determine size of the object
|
||||
// -------------------------------
|
||||
float x_min, x_max, y_min, y_max, z_min, z_max, radius;
|
||||
MinMax(this, &x_min, &x_max, &y_min, &y_max, &z_min, &z_max);
|
||||
m_half_height = 0.5f*(z_max-z_min);
|
||||
Vec3 min, max;
|
||||
SSGHelp::MinMax(this, &min, &max);
|
||||
Vec3 extend = max-min;
|
||||
m_half_height = 0.5f*(extend.getZ());
|
||||
switch (m_body_type)
|
||||
{
|
||||
case MP_CONE: radius = 0.5f*std::max(x_max-x_min, y_max-y_min);
|
||||
m_shape = new btConeShapeZ(radius, z_max-z_min);
|
||||
case MP_CONE: {
|
||||
float radius = 0.5f*std::max(extend.getX(), extend.getY());
|
||||
m_shape = new btConeShapeZ(radius, extend.getZ());
|
||||
setName("cone");
|
||||
break;
|
||||
case MP_BOX: m_shape = new btBoxShape(btVector3(0.5f*(x_max-x_min),
|
||||
0.5f*(y_max-y_min),
|
||||
0.5f*(z_max-z_min) ) );
|
||||
}
|
||||
case MP_BOX: m_shape = new btBoxShape(0.5*extend);
|
||||
setName("box");
|
||||
break;
|
||||
case MP_SPHERE: radius = std::max(x_max-x_min, y_max-y_min);
|
||||
radius = 0.5f*std::max(radius, z_max-z_min);
|
||||
case MP_SPHERE: {
|
||||
float radius = std::max(extend.getX(), extend.getY());
|
||||
radius = 0.5f*std::max(radius, extend.getZ());
|
||||
m_shape = new btSphereShape(radius);
|
||||
setName("sphere");
|
||||
break;
|
||||
}
|
||||
case MP_NONE: fprintf(stderr, "WARNING: Uninitialised moving shape\n");
|
||||
break;
|
||||
}
|
||||
|
@ -18,41 +18,46 @@
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "physics.hpp"
|
||||
#include "ssg_help.hpp"
|
||||
|
||||
#include "world.hpp"
|
||||
#include "flyable.hpp"
|
||||
#include "moving_physics.hpp"
|
||||
#include "user_config.hpp"
|
||||
#include "material_manager.hpp"
|
||||
#include "network/race_state.hpp"
|
||||
#include "utils/ssg_help.hpp"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Initialise physics.
|
||||
* Create the bullet dynamics world.
|
||||
*/
|
||||
Physics::Physics(float gravity) : btSequentialImpulseConstraintSolver()
|
||||
Physics::Physics() : btSequentialImpulseConstraintSolver()
|
||||
{
|
||||
m_collision_conf = new btDefaultCollisionConfiguration();
|
||||
m_dispatcher = new btCollisionDispatcher(m_collision_conf);
|
||||
|
||||
// FIXME: it might be better to use the track dimension here, but they
|
||||
// are not known at this stage.
|
||||
btVector3 worldMin(-1000, -1000, -1000);
|
||||
btVector3 worldMax( 1000, 1000, 1000);
|
||||
m_axis_sweep = new btAxisSweep3(worldMin, worldMax);
|
||||
} // Physics
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** The actual initialisation of the physics, which is called after the track
|
||||
* model is loaded. This allows the physics to use the actual track dimension
|
||||
* for the axis sweep.
|
||||
*/
|
||||
void Physics::init(const Vec3 &world_min, const Vec3 &world_max)
|
||||
{
|
||||
m_axis_sweep = new btAxisSweep3(world_min, world_max);
|
||||
m_dynamics_world = new btDiscreteDynamicsWorld(m_dispatcher,
|
||||
m_axis_sweep,
|
||||
this,
|
||||
m_collision_conf);
|
||||
m_dynamics_world->setGravity(btVector3(0.0f, 0.0f, -gravity));
|
||||
m_dynamics_world->setGravity(btVector3(0.0f, 0.0f,
|
||||
-world->getTrack()->getGravity()));
|
||||
if(user_config->m_bullet_debug)
|
||||
{
|
||||
m_debug_drawer=new GLDebugDrawer();
|
||||
m_debug_drawer->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
|
||||
m_dynamics_world->setDebugDrawer(m_debug_drawer);
|
||||
}
|
||||
} // Physics
|
||||
|
||||
} // init
|
||||
//-----------------------------------------------------------------------------
|
||||
Physics::~Physics()
|
||||
{
|
||||
|
@ -69,9 +69,9 @@ private:
|
||||
}; // CollisionPair
|
||||
bool operator==(const CollisionPair p) {
|
||||
return (p.a==a && p.b==b);
|
||||
}
|
||||
};
|
||||
|
||||
} // operator==
|
||||
}; // CollisionPair
|
||||
// ------------------------------------------------------------------------
|
||||
// This class is the list of collision objects, where each collision
|
||||
// pair is stored as most once.
|
||||
class CollisionList : public std::vector<CollisionPair> {
|
||||
@ -88,12 +88,13 @@ private:
|
||||
push_back(CollisionPair(a, b));
|
||||
}
|
||||
}; // CollisionList
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
CollisionList m_all_collisions;
|
||||
|
||||
public:
|
||||
Physics (float gravity);
|
||||
Physics ();
|
||||
~Physics ();
|
||||
void init (const Vec3 &min_world, const Vec3 &max_world);
|
||||
void addKart (const Kart *k, btRaycastVehicle *v);
|
||||
void addBody (btRigidBody* b) {m_dynamics_world->addRigidBody(b);}
|
||||
void removeKart (const Kart *k);
|
||||
|
216
src/ssg_help.cpp
216
src/ssg_help.cpp
@ -1,216 +0,0 @@
|
||||
// $Id: ssg_help.cpp 837 2006-10-23 07:43:05Z hiker $
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
|
||||
// Copyright (C) 2006 SuperTuxKart-Team, Joerg Henrichs, Steve Baker
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <plib/ssg.h>
|
||||
#include "ssg_help.hpp"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Make VtTables use display lists.
|
||||
*
|
||||
* Calls recursively 'makeDList' in all ssgVtxTable of the entity.
|
||||
* \param entity Tree in which to create display lists.
|
||||
*/
|
||||
void createDisplayLists(ssgEntity* entity)
|
||||
{
|
||||
if (!entity) return;
|
||||
|
||||
ssgVtxTable* table = dynamic_cast<ssgVtxTable*>(entity);
|
||||
if(table)
|
||||
{
|
||||
if(table->getNumTriangles()>1) table->makeDList();
|
||||
}
|
||||
ssgBranch* branch = dynamic_cast<ssgBranch*>(entity);
|
||||
|
||||
if (branch)
|
||||
{
|
||||
for(ssgEntity* i = branch->getKid(0); i != NULL;
|
||||
i = branch->getNextKid())
|
||||
{
|
||||
createDisplayLists(i);
|
||||
} // for
|
||||
} // if branch
|
||||
|
||||
} // createDisplayLists
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Adds a transform node to the branch.
|
||||
*
|
||||
* Creates a new ssgTransform node to which all children of the branch are
|
||||
* added. The new ssgTransform is then set as the only child of the
|
||||
* branch.
|
||||
* \param branch The branch to which a transform node is added.
|
||||
*/
|
||||
ssgTransform* add_transform(ssgBranch* branch)
|
||||
{
|
||||
if (!branch) return 0;
|
||||
|
||||
ssgTransform* transform = new ssgTransform;
|
||||
transform->ref();
|
||||
for(ssgEntity* i = branch->getKid(0); i != NULL; i = branch->getNextKid())
|
||||
{
|
||||
transform->addKid(i);
|
||||
}
|
||||
|
||||
branch->removeAllKids();
|
||||
branch->addKid(transform);
|
||||
|
||||
// Set some user data, so that the wheel isn't ssgFlatten()'ed
|
||||
branch->setUserData(new ssgBase());
|
||||
transform->setUserData(new ssgBase());
|
||||
|
||||
return transform;
|
||||
} // add_transform
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Recursively prints a model.
|
||||
*
|
||||
* Recursively prints a model. That function can most likely be removed, the
|
||||
* print method of the ssg objects do the same.
|
||||
* \param entity The entity ro print (can't be constant because of ssg functions
|
||||
* which are not const correct)
|
||||
* \param indent Indentation to use
|
||||
* \param maxLevel maximum number of levels to print
|
||||
*/
|
||||
void print_model(ssgEntity* entity, const int indent, const int maxLevel)
|
||||
{
|
||||
if(maxLevel <0) return;
|
||||
if (entity)
|
||||
{
|
||||
for(int i = 0; i < indent; ++i)
|
||||
std::cout << " ";
|
||||
|
||||
std::cout << entity->getTypeName() << " " << entity->getType() << " '"
|
||||
<< entity->getPrintableName()
|
||||
<< "' '"
|
||||
<< (entity->getName() ? entity->getName() : "null")
|
||||
<< "' " << entity << std::endl;
|
||||
|
||||
ssgBranch* branch = dynamic_cast<ssgBranch*>(entity);
|
||||
|
||||
if (branch)
|
||||
{
|
||||
for(ssgEntity* i = branch->getKid(0); i != NULL;
|
||||
i = branch->getNextKid())
|
||||
{
|
||||
print_model(i, indent + 1, maxLevel-1);
|
||||
}
|
||||
} // if branch
|
||||
} // if entity
|
||||
} // print_model
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Computes the minimum and maximum x/y coordinates for a ssgEntity.
|
||||
*
|
||||
* Recursively computes the minimum x and y coordinates of a ssgEntity.
|
||||
* \param p ssgEntity for which t compute the extend (can't be constant because
|
||||
* of plib not const correct)
|
||||
* \param x_min minimum x value
|
||||
* \param x_max maximum x value
|
||||
* \param y_min minimum y value
|
||||
* \param y_max maximum y value
|
||||
* \param z_min minimum z value, optional parameter!
|
||||
* \param z_max minimum z value, optional parameter!
|
||||
*/
|
||||
void MinMax(ssgEntity* p, float *x_min, float *x_max,
|
||||
float *y_min, float *y_max,
|
||||
float *z_min, float *z_max)
|
||||
{
|
||||
sgMat4 mat;
|
||||
sgMakeIdentMat4(mat);
|
||||
*x_min = *y_min = 10000.0f; if(z_min) *z_min = 10000.0f;
|
||||
*x_max = *y_max = -10000.0f; if(z_max) *z_max = -10000.0f;
|
||||
MinMax(p, mat, x_min, x_max, y_min, y_max, z_min, z_max);
|
||||
|
||||
} // MinMax
|
||||
|
||||
/** Internal function used by MinMax. */
|
||||
void MinMax(ssgEntity* p, sgMat4 m, float* x_min, float* x_max,
|
||||
float* y_min, float* y_max,
|
||||
float* z_min, float* z_max)
|
||||
{
|
||||
if(p->isAKindOf(ssgTypeLeaf()))
|
||||
{
|
||||
ssgLeaf* l=(ssgLeaf*)p;
|
||||
for(int i=0; i<l->getNumTriangles(); i++)
|
||||
{
|
||||
short v1,v2,v3;
|
||||
sgVec3 vv1, vv2, vv3;
|
||||
|
||||
l->getTriangle(i, &v1, &v2, &v3);
|
||||
|
||||
sgXformPnt3 ( vv1, l->getVertex(v1), m );
|
||||
sgXformPnt3 ( vv2, l->getVertex(v2), m );
|
||||
sgXformPnt3 ( vv3, l->getVertex(v3), m );
|
||||
*x_min = std::min(*x_min, vv1[0]); *x_max = std::max(*x_max, vv1[0]);
|
||||
*x_min = std::min(*x_min, vv2[0]); *x_max = std::max(*x_max, vv2[0]);
|
||||
*x_min = std::min(*x_min, vv3[0]); *x_max = std::max(*x_max, vv3[0]);
|
||||
*y_min = std::min(*y_min, vv1[1]); *y_max = std::max(*y_max, vv1[1]);
|
||||
*y_min = std::min(*y_min, vv2[1]); *y_max = std::max(*y_max, vv2[1]);
|
||||
*y_min = std::min(*y_min, vv3[1]); *y_max = std::max(*y_max, vv3[1]);
|
||||
if(z_min)
|
||||
{
|
||||
*z_min = std::min(*z_min, vv1[2]);
|
||||
*z_min = std::min(*z_min, vv2[2]);
|
||||
*z_min = std::min(*z_min, vv3[2]);
|
||||
}
|
||||
if(z_max)
|
||||
{
|
||||
*z_max = std::max(*z_max, vv1[2]);
|
||||
*z_max = std::max(*z_max, vv2[2]);
|
||||
*z_max = std::max(*z_max, vv3[2]);
|
||||
}
|
||||
|
||||
} // for i<p->getNumTriangles
|
||||
}
|
||||
else if (p->isAKindOf(ssgTypeTransform()))
|
||||
{
|
||||
ssgBaseTransform* t=(ssgBaseTransform*)p;
|
||||
|
||||
sgMat4 tmpT, tmpM;
|
||||
t->getTransform(tmpT);
|
||||
sgCopyMat4(tmpM, m);
|
||||
sgPreMultMat4(tmpM,tmpT);
|
||||
|
||||
for(ssgEntity* e=t->getKid(0); e!=NULL; e=t->getNextKid())
|
||||
{
|
||||
MinMax(e, tmpM, x_min, x_max, y_min, y_max, z_min, z_max);
|
||||
} // for i<getNumKids
|
||||
|
||||
}
|
||||
else if (p->isAKindOf(ssgTypeBranch()))
|
||||
{
|
||||
ssgBranch* b =(ssgBranch*)p;
|
||||
for(ssgEntity* e=b->getKid(0); e!=NULL; e=b->getNextKid())
|
||||
{
|
||||
MinMax(e, m, x_min, x_max, y_min, y_max, z_min, z_max);
|
||||
} // for i<getNumKids
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("StaticSSG::MinMax: unkown type\n");
|
||||
p->print(stdout, 0, 0);
|
||||
}
|
||||
} // MinMax
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/* EOF */
|
@ -18,11 +18,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#include <algorithm>
|
||||
|
||||
#include "static_ssg.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "material_manager.hpp"
|
||||
#include "material.hpp"
|
||||
#include "ssg_help.hpp"
|
||||
#include "utils/ssg_help.hpp"
|
||||
|
||||
#ifndef round
|
||||
# define round(x) (floor(x+0.5f))
|
||||
@ -41,7 +44,12 @@ StaticSSG::StaticSSG(ssgEntity* start_, int nSize)
|
||||
void StaticSSG::Setup(int nSize)
|
||||
{
|
||||
// First compute the minimum and maximum x/y values of all leaves
|
||||
MinMax(m_start, &m_x_min, &m_x_max, &m_y_min, &m_y_max);
|
||||
Vec3 min, max;
|
||||
SSGHelp::MinMax(m_start, &min, &max);
|
||||
m_x_min = min.getX();
|
||||
m_x_max = max.getX();
|
||||
m_y_min = min.getY();
|
||||
m_y_max = max.getY();
|
||||
|
||||
const float RATIO = (m_x_max-m_x_min)/(m_y_max-m_y_min);
|
||||
|
||||
|
@ -17,14 +17,16 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "track.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#define _WINSOCKAPI_
|
||||
#include <plib/ssgAux.h>
|
||||
|
||||
#include "file_manager.hpp"
|
||||
#include "loader.hpp"
|
||||
#include "track.hpp"
|
||||
#include "string_utils.hpp"
|
||||
#include "lisp/lisp.hpp"
|
||||
#include "lisp/parser.hpp"
|
||||
@ -35,12 +37,12 @@
|
||||
#include "world.hpp"
|
||||
#include "material_manager.hpp"
|
||||
#include "isect.hpp"
|
||||
#include "ssg_help.hpp"
|
||||
#include "user_config.hpp"
|
||||
#include "herring.hpp"
|
||||
#include "herring_manager.hpp"
|
||||
#include "audio/sound_manager.hpp"
|
||||
#include "race_manager.hpp"
|
||||
#include "audio/sound_manager.hpp"
|
||||
#include "utils/ssg_help.hpp"
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
# define snprintf _snprintf
|
||||
@ -1278,7 +1280,7 @@ void Track::loadTrackModel()
|
||||
file_manager->popModelSearchPath ();
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
createDisplayLists(obj);
|
||||
SSGHelp::createDisplayLists(obj);
|
||||
ssgRangeSelector *lod = new ssgRangeSelector ;
|
||||
ssgTransform *trans = new ssgTransform ( & loc ) ;
|
||||
|
||||
@ -1307,6 +1309,9 @@ void Track::loadTrackModel()
|
||||
file_manager->popTextureSearchPath();
|
||||
file_manager->popModelSearchPath ();
|
||||
|
||||
Vec3 min, max;
|
||||
SSGHelp::MinMax(m_model, &min, &max);
|
||||
world->getPhysics()->init(min, max);
|
||||
createPhysicsModel();
|
||||
} // loadTrack
|
||||
|
||||
|
205
src/utils/ssg_help.cpp
Normal file
205
src/utils/ssg_help.cpp
Normal file
@ -0,0 +1,205 @@
|
||||
// $Id: ssg_help.cpp 837 2006-10-23 07:43:05Z hiker $
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
|
||||
// Copyright (C) 2006 SuperTuxKart-Team, Joerg Henrichs, Steve Baker
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "utils/ssg_help.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <plib/ssg.h>
|
||||
|
||||
namespace SSGHelp
|
||||
{
|
||||
// ------------------------------------------------------------------------
|
||||
/** Make VtTables use display lists.
|
||||
*
|
||||
* Calls recursively 'makeDList' in all ssgVtxTable of the entity.
|
||||
* \param entity Tree in which to create display lists.
|
||||
*/
|
||||
void createDisplayLists(ssgEntity* entity)
|
||||
{
|
||||
if (!entity) return;
|
||||
|
||||
ssgVtxTable* table = dynamic_cast<ssgVtxTable*>(entity);
|
||||
if(table)
|
||||
{
|
||||
if(table->getNumTriangles()>1) table->makeDList();
|
||||
}
|
||||
ssgBranch* branch = dynamic_cast<ssgBranch*>(entity);
|
||||
|
||||
if (branch)
|
||||
{
|
||||
for(ssgEntity* i = branch->getKid(0); i != NULL;
|
||||
i = branch->getNextKid())
|
||||
{
|
||||
createDisplayLists(i);
|
||||
} // for
|
||||
} // if branch
|
||||
|
||||
} // createDisplayLists
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
/** Adds a transform node to the branch.
|
||||
*
|
||||
* Creates a new ssgTransform node to which all children of the branch are
|
||||
* added. The new ssgTransform is then set as the only child of the
|
||||
* branch.
|
||||
* \param branch The branch to which a transform node is added.
|
||||
*/
|
||||
ssgTransform* add_transform(ssgBranch* branch)
|
||||
{
|
||||
if (!branch) return 0;
|
||||
|
||||
ssgTransform* transform = new ssgTransform;
|
||||
transform->ref();
|
||||
for(ssgEntity* i = branch->getKid(0); i != NULL;
|
||||
i = branch->getNextKid())
|
||||
{
|
||||
transform->addKid(i);
|
||||
}
|
||||
|
||||
branch->removeAllKids();
|
||||
branch->addKid(transform);
|
||||
|
||||
// Set some user data, so that the wheel isn't ssgFlatten()'ed
|
||||
branch->setUserData(new ssgBase());
|
||||
transform->setUserData(new ssgBase());
|
||||
|
||||
return transform;
|
||||
} // add_transform
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Recursively prints a model.
|
||||
*
|
||||
* Recursively prints a model. That function can most likely be removed, the
|
||||
* print method of the ssg objects do the same.
|
||||
* \param entity The entity ro print (can't be constant because of ssg
|
||||
* functions which are not const correct)
|
||||
* \param indent Indentation to use
|
||||
* \param maxLevel maximum number of levels to print
|
||||
*/
|
||||
void print_model(ssgEntity* entity, const int indent, const int maxLevel)
|
||||
{
|
||||
if(maxLevel <0) return;
|
||||
if (entity)
|
||||
{
|
||||
for(int i = 0; i < indent; ++i)
|
||||
std::cout << " ";
|
||||
|
||||
std::cout << entity->getTypeName() << " " << entity->getType()
|
||||
<< " '"
|
||||
<< entity->getPrintableName()
|
||||
<< "' '"
|
||||
<< (entity->getName() ? entity->getName() : "null")
|
||||
<< "' " << entity << std::endl;
|
||||
|
||||
ssgBranch* branch = dynamic_cast<ssgBranch*>(entity);
|
||||
|
||||
if (branch)
|
||||
{
|
||||
for(ssgEntity* i = branch->getKid(0); i != NULL;
|
||||
i = branch->getNextKid())
|
||||
{
|
||||
print_model(i, indent + 1, maxLevel-1);
|
||||
}
|
||||
} // if branch
|
||||
} // if entity
|
||||
} // print_model
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** MinMax helper function which uses a transform and then computes the
|
||||
* minimum/maximum for this subtree.
|
||||
* \param p Subtree.
|
||||
* \param m Transformation to apply.
|
||||
* \param min On return contains the minimum.
|
||||
* \param max On return contains the maximum.
|
||||
*/
|
||||
static void MinMaxInternal(const ssgEntity* p, sgMat4 m, Vec3 *min, Vec3 *max)
|
||||
{
|
||||
if(const_cast<ssgEntity*>(p)->isAKindOf(ssgTypeLeaf()))
|
||||
{
|
||||
ssgLeaf* l=(ssgLeaf*)p;
|
||||
for(int i=0; i<l->getNumTriangles(); i++)
|
||||
{
|
||||
short v1,v2,v3;
|
||||
sgVec3 vv1, vv2, vv3;
|
||||
|
||||
l->getTriangle(i, &v1, &v2, &v3);
|
||||
|
||||
sgXformPnt3 ( vv1, l->getVertex(v1), m );
|
||||
sgXformPnt3 ( vv2, l->getVertex(v2), m );
|
||||
sgXformPnt3 ( vv3, l->getVertex(v3), m );
|
||||
Vec3 vec3vv1(vv1);
|
||||
Vec3 vec3vv2(vv2);
|
||||
Vec3 vec3vv3(vv3);
|
||||
min->min(vec3vv1);
|
||||
min->min(vec3vv2);
|
||||
min->min(vec3vv3);
|
||||
max->max(vec3vv1);
|
||||
max->max(vec3vv2);
|
||||
max->max(vec3vv3);
|
||||
} // for i<p->getNumTriangles
|
||||
}
|
||||
else if (const_cast<ssgEntity*>(p)->isAKindOf(ssgTypeTransform()))
|
||||
{
|
||||
ssgBaseTransform* t=(ssgBaseTransform*)p;
|
||||
|
||||
sgMat4 tmpT, tmpM;
|
||||
t->getTransform(tmpT);
|
||||
sgCopyMat4(tmpM, m);
|
||||
sgPreMultMat4(tmpM,tmpT);
|
||||
|
||||
for(ssgEntity* e=t->getKid(0); e!=NULL; e=t->getNextKid())
|
||||
{
|
||||
MinMaxInternal(e, tmpM, min, max);
|
||||
} // for i<getNumKids
|
||||
|
||||
}
|
||||
else if (const_cast<ssgEntity*>(p)->isAKindOf(ssgTypeBranch()))
|
||||
{
|
||||
ssgBranch* b =(ssgBranch*)p;
|
||||
for(ssgEntity* e=b->getKid(0); e!=NULL; e=b->getNextKid())
|
||||
{
|
||||
MinMaxInternal(e, m, min, max);
|
||||
} // for i<getNumKids
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("StaticSSG::MinMax: unkown type\n");
|
||||
const_cast<ssgEntity*>(p)->print(stdout, 0, 0);
|
||||
}
|
||||
} // MinMaxInternal
|
||||
// ------------------------------------------------------------------------
|
||||
/** Computes the minimum and maximum x/y coordinates for a ssgEntity.
|
||||
*
|
||||
* Recursively computes the minimum x and y coordinates of a ssgEntity.
|
||||
* \param p ssgEntity for which t compute the extend.
|
||||
* \param min Minimum values in all three dimensions.
|
||||
* \param max Maximum values in all three dimensions.
|
||||
*/
|
||||
void MinMax(const ssgEntity* p, Vec3 *min, Vec3 *max)
|
||||
{
|
||||
sgMat4 mat;
|
||||
sgMakeIdentMat4(mat);
|
||||
*min = Vec3(10000.0f);
|
||||
*max = Vec3(-10000.0f);
|
||||
MinMaxInternal(p, mat,min, max);
|
||||
} // Minmax
|
||||
|
||||
} // namespace SSGHelp
|
||||
/* EOF */
|
@ -22,22 +22,17 @@
|
||||
#define HEADER_SSG_HELP_H
|
||||
|
||||
#include <plib/ssg.h>
|
||||
#include "vec3.hpp"
|
||||
|
||||
//* Several useful functions which don't fit anywhere else
|
||||
void createDisplayLists(ssgEntity *entity);
|
||||
ssgTransform* add_transform (ssgBranch* branch);
|
||||
void print_model (ssgEntity *entity, const int indent,
|
||||
const int maxLevel);
|
||||
void MinMax (ssgEntity *p,
|
||||
float *x_min, float *x_max,
|
||||
float *y_min, float *y_max,
|
||||
float *z_min=NULL, float *z_max=NULL);
|
||||
void MinMax (ssgEntity *p, sgMat4 m,
|
||||
float *x_min, float *x_max,
|
||||
float *y_min, float *y_max,
|
||||
float *z_min=NULL, float *z_max=NULL);
|
||||
|
||||
|
||||
namespace SSGHelp {
|
||||
//* Several useful functions which don't fit anywhere else
|
||||
void createDisplayLists(ssgEntity *entity);
|
||||
ssgTransform* add_transform (ssgBranch* branch);
|
||||
void print_model (ssgEntity *entity, const int indent,
|
||||
const int maxLevel);
|
||||
void MinMax (const ssgEntity *p,
|
||||
Vec3 *min, Vec3 *max);
|
||||
}; // namespace SSGHelp
|
||||
#endif
|
||||
|
||||
/* EOF */
|
@ -93,7 +93,7 @@ World::World()
|
||||
}
|
||||
|
||||
// Create the physics
|
||||
m_physics = new Physics(m_track->getGravity());
|
||||
m_physics = new Physics();
|
||||
|
||||
assert(race_manager->getNumKarts() > 0);
|
||||
|
||||
@ -737,6 +737,9 @@ void World::updateRacePosition ( int k )
|
||||
} // updateRacePosition
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Cleans up old herrings (from a previous race), removes old track specific
|
||||
* herring models, and loads the actual track.
|
||||
*/
|
||||
void World::loadTrack()
|
||||
{
|
||||
// remove old herrings (from previous race), and remove old
|
||||
|
Loading…
Reference in New Issue
Block a user