21 #include <sys/types.h> 60 ssgSimpleState *
mst = NULL;
70 const int BUFSIZE = 256;
87 timeSmoke = (
double *) malloc(
sizeof(
double)*index*4);
88 memset(
timeSmoke,0,
sizeof(
double)*index*4);
92 timeFire = (
double *) malloc(
sizeof(
double)*index);
93 memset(
timeFire,0,
sizeof(
double)*index);
104 snprintf(buf, BUFSIZE,
"data/textures;data/img;.");
107 mst->disable(GL_LIGHTING);
108 mst->enable(GL_BLEND);
109 mst->disable(GL_CULL_FACE);
110 mst->setTranslucent();
111 mst->setColourMaterial(GL_AMBIENT_AND_DIFFUSE);
118 snprintf(buf, BUFSIZE,
"data/textures;data/img;.");
121 mstf0->disable(GL_LIGHTING);
122 mstf0->enable(GL_BLEND);
123 mstf0->disable(GL_CULL_FACE);
124 mstf0->setTranslucent();
125 mstf0->setColourMaterial(GL_AMBIENT_AND_DIFFUSE);
132 snprintf(buf, BUFSIZE,
"data/textures;data/img;.");
135 mstf1->disable(GL_LIGHTING);
136 mstf1->enable(GL_BLEND);
137 mstf1->disable(GL_CULL_FACE);
138 mstf1->setTranslucent();
139 mstf1->setColourMaterial(GL_AMBIENT_AND_DIFFUSE);
159 while( tmp != NULL) {
199 sgVec3 *vx = (sgVec3 *) tmp->
smoke->getVertices()->get(0) ;
226 ssgVertexArray *shd_vtx ;
235 for (i = 0; i < 4; i++) {
246 tdble threshold = 0.1f;
247 tdble smoke_life_coefficient = 30.0f;
248 tdble smoke_speed_coefficient = 0.0f;
257 if (strstr(surface,
"sand")) {
259 cur_clr[1] = 0.7f +
urandom()*0.1f;
260 cur_clr[2] = 0.4f +
urandom()*0.2f;
263 smoke_life_coefficient = 12.5f;
264 smoke_speed_coefficient = 0.25f;
265 }
else if (strstr(surface,
"dirt")) {
266 cur_clr[0] = 0.7f +
urandom()*0.1f;
267 cur_clr[1] = 0.6f +
urandom()*0.1f;
268 cur_clr[2] = 0.5f +
urandom()*0.1f;
271 smoke_life_coefficient = 10.0f;
272 smoke_speed_coefficient = 0.5f;
273 }
else if (strstr(surface,
"mud")) {
275 cur_clr[1] = 0.4f +
urandom()*0.2f;
276 cur_clr[2] = 0.3f +
urandom()*0.2f;
279 smoke_speed_coefficient = 0.05f;
280 }
else if (strstr(surface,
"gravel")) {
285 smoke_life_coefficient = 20.0f;
286 smoke_speed_coefficient = 0.1f;
287 }
else if (strstr(surface,
"grass")) {
288 cur_clr[0] = 0.4f +
urandom()*0.2f;
289 cur_clr[1] = 0.5f +
urandom()*0.1f;
290 cur_clr[2] = 0.3f +
urandom()*0.1f;
292 smoke_life_coefficient = 25.0f;
301 smoke_life_coefficient = smoke_life_coefficient * (1.0f -
urandom()*
urandom());
302 tdble spd_fx=tanh(0.001f*car->_reaction[i])*smoke_speed_coefficient*car->
pub.
speed;
303 if (car->_skid[i] + 0.025f*
urandom()*spd_fx>
urandom() + threshold) {
305 float init_speed_z = 0.1f;
306 float stretch_factor = 0.5f;
307 tdble sinCarYaw = sin(car->_yaw);
308 tdble cosCarYaw = cos(car->_yaw);
310 shd_vtx =
new ssgVertexArray(1);
317 tdble stretchX = 0.1f * (spd_fx + stretch_factor * fabs(car->_speed_X));
318 tdble stretchY = 0.1f * (spd_fx + stretch_factor * fabs(car->_speed_Y));
319 vtx[0] -= 0.05f*car->_speed_x;
323 init_speed =
urandom()*init_speed;
325 tmp->
smoke->
vvx = -sinCarYaw * car->_wheelSlipSide(i);
326 tmp->
smoke->
vvy = cosCarYaw * car->_wheelSlipSide(i);
327 tmp->
smoke->
vvx += cosCarYaw * car->_wheelSlipAccel(i);
328 tmp->
smoke->
vvy += sinCarYaw * car->_wheelSlipAccel(i);
335 tmp->
smoke->setCullFace(0);
339 (car->_skid[i]*car->
pub.
speed+
urandom()*spd_fx)/ smoke_life_coefficient;
340 for (
int c = 0; c < 3; c++) {
369 if (car->_exhaustNb && (car->
pub.
speed > 3.0f)) {
386 for (i = 0; i < car->_exhaustNb; i++) {
387 shd_vtx =
new ssgVertexArray(1);
389 vtx[0] = car->_exhaustPos[i].x;
390 vtx[1] = car->_exhaustPos[i].y;
391 vtx[2] = car->_exhaustPos[i].z;
397 tmp->
smoke->setCullFace(0);
433 GfOut(
"-- grShutdownSmoke\n");
465 ssgDeRefDelete(
mstf0);
470 ssgDeRefDelete(
mstf1);
477 ssgVtxTable::copy_from ( src, clone_flags ) ;
493 gltype = GL_TRIANGLE_STRIP;
494 type = ssgTypeVtxTable () ;
496 vertices = (shd_vtx!=NULL) ? shd_vtx :
new ssgVertexArray () ;
497 normals =
new ssgNormalArray () ;
498 texcoords =
new ssgTexCoordArray () ;
499 colours =
new ssgColourArray () ;
503 texcoords -> ref () ;
520 GLfloat modelView[16];
522 sgVec3 right, up, offset;
524 sgVec3 *vx = (sgVec3 *) vertices->get(0);
525 sgVec3 *nm = (sgVec3 *) normals->get(0);
526 sgVec4 *cl = (sgVec4 *) colours->get(0);
528 glDepthMask(GL_FALSE);
529 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
540 glGetFloatv(GL_MODELVIEW_MATRIX, modelView);
544 offset[0] = offset[1] = offset[2] = 0.0f;
547 for (i = 0; i < 3; i++) {
550 for (k = 0; k < 4; k++, j+=4) {
552 offset[i] += modelView[j] * vx[0][k];
554 offset[i] += modelView[j];
560 tdble dist = sqrt(offset[0]*offset[0]
561 + offset[1]*offset[1]
562 + offset[2]*offset[2]);
564 up[0] = modelView[1];
565 up[1] = modelView[5];
566 up[2] = modelView[9];
568 right[0] = modelView[0];
569 right[1] = modelView[4];
570 right[2] = modelView[8];
575 C[0] = right[0]+up[0];
576 C[1] = right[1]+up[1];
577 C[2] = right[2]+up[2];
580 D[0] = -right[0]+up[0];
581 D[1] = -right[1]+up[1];
582 D[2] = -right[2]+up[2];
585 A[0] = -right[0]-up[0];
586 A[1] = -right[1]-up[1];
587 A[2] = -right[2]-up[2];
590 B[0] = right[0]-up[0];
591 B[1] = right[1]-up[1];
592 B[2] = right[2]-up[2];
597 alpha *= (1.0f - exp(-0.1f * dist));
601 if (num_colours == 1) {
604 if (num_normals == 1) {
610 glVertex3f(vx[0][0]+
sizex*A[0],vx[0][1]+
sizey*A[1], vx[0][2]+
sizez*A[2]);
612 glVertex3f(vx[0][0]+
sizex*B[0],vx[0][1]+
sizey*B[1], vx[0][2]+
sizez*B[2]);
614 glVertex3f(vx[0][0]+
sizex*D[0],vx[0][1]+
sizey*D[1], vx[0][2]+
sizez*D[2]);
616 glVertex3f(vx[0][0]+
sizex*C[0],vx[0][1]+
sizey*C[1], vx[0][2]+
sizez*C[2]);
619 glDisable(GL_POLYGON_OFFSET_FILL);
620 glDepthMask(GL_TRUE);
621 glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
void grAddSmoke(tCarElt *car, double t)
#define GR_ATT_SMOKEDELTAT
virtual void copy_from(ssgVtxTableSmoke *src, int clone_flags)
virtual void transform(const sgMat4 m)
The Gaming Framework API (client part).
#define SMOKE_TYPE_ENGINE
void grInitSmoke(int index)
const char * material
Type of material used.
tPosd relPos
position relative to GC
void grShutdownSmoke()
remove the smoke information for a car
void grUpdateSmoke(double t)
update if necessary the smoke for a car
ssgSimpleState * mst
initialize the smoke structure
virtual ssgBase * clone(int clone_flags=0)
tgrCarInstrument instrument[2]
float tdble
Floating point type used in TORCS.
Graphic Module Interface Definition.
This is the car structure.
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
tTrackSeg * seg
Track segment where the wheel is.
tTrackSurface * surface
Segment surface.
ssgState * grSsgLoadTexStateEx(const char *img, char *filepath, int wrap, int mipmap)
virtual ~ssgVtxTableSmoke(void)
Track Structure and Track Loader Module Definition.
static tgrSmokeManager * smokeManager
#define GR_ATT_SMOKEDLIFE