2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
23 extern float viewdistance;
24 extern float fadestart;
25 extern int environment;
26 extern float texscale;
28 extern float multiplier;
30 extern FRUSTUM frustum;
31 extern Terrain terrain;
34 extern float blurness;
36 extern float playerdist;
37 extern bool skyboxtexture;
41 bool Objects::checkcollide(XYZ startpoint, XYZ endpoint, int which)
43 static XYZ colpoint, colviewer, coltarget;
51 for (i = 0; i < numobjects; i++) {
52 if (type[i] != treeleavestype && type[i] != treetrunktype && type[i] != bushtype && type[i] != firetype && i != which) {
53 colviewer = startpoint;
55 if (model[i].LineCheck(&colviewer, &coltarget, &colpoint, &position[i], &yaw[i]) != -1)
63 void Objects::SphereCheckPossible(XYZ *p1, float radius)
66 static int whichpatchx;
67 static int whichpatchz;
69 whichpatchx = p1->x / (terrain.size / subdivision * terrain.scale);
70 whichpatchz = p1->z / (terrain.size / subdivision * terrain.scale);
72 if (whichpatchx >= 0 && whichpatchz >= 0 && whichpatchx < subdivision && whichpatchz < subdivision)
73 if (terrain.patchobjectnum[whichpatchx][whichpatchz] > 0 && terrain.patchobjectnum[whichpatchx][whichpatchz] < 500)
74 for (j = 0; j < terrain.patchobjectnum[whichpatchx][whichpatchz]; j++) {
75 i = terrain.patchobjects[whichpatchx][whichpatchz][j];
77 if (model[i].SphereCheckPossible(p1, radius, &position[i], &yaw[i]) != -1) {
85 static float distance;
87 static XYZ moved, terrainlight;
90 for (i = 0; i < numobjects; i++) {
91 if (type[i] != firetype) {
92 moved = DoRotation(model[i].boundingspherecenter, 0, yaw[i], 0);
93 if (type[i] == tunneltype || frustum.SphereInFrustum(position[i].x + moved.x, position[i].y + moved.y, position[i].z + moved.z, model[i].boundingsphereradius)) {
94 distance = distsq(&viewer, &position[i]);
96 hidden = !(distsqflat(&viewer, &position[i]) > playerdist + 3 || (type[i] != bushtype && type[i] != treeleavestype));
99 if (detail == 2 && distance > viewdistance * viewdistance / 4 && environment == desertenvironment)
100 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness );
102 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
103 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
108 if (occluded[i] < 6) {
109 glMatrixMode(GL_MODELVIEW);
112 glEnable(GL_LIGHTING);
114 glDisable(GL_LIGHTING);
116 glTranslatef(position[i].x, position[i].y, position[i].z);
117 if (type[i] == bushtype) {
118 messedwith[i] -= multiplier;
119 if (rotxvel[i] || rotx[i]) {
120 if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
121 if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
122 if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
123 if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
124 if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
125 if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
126 if (fabs(rotx[i]) < multiplier * 4)
128 if (fabs(rotxvel[i]) < multiplier * 4)
131 rotx[i] += rotxvel[i] * multiplier * 4;
133 if (rotyvel[i] || roty[i]) {
134 if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
135 if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
136 if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
137 if (roty[i] < 0) rotyvel[i] += multiplier * 4;
138 if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
139 if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
140 if (fabs(roty[i]) < multiplier * 4)
142 if (fabs(rotyvel[i]) < multiplier * 4)
145 roty[i] += rotyvel[i] * multiplier * 4;
148 glRotatef(roty[i], 1, 0, 0);
151 glRotatef(-rotx[i], 0, 0, 1);
162 if (type[i] == treetrunktype || type[i] == treeleavestype) {
163 if (type[i] == treetrunktype || environment == desertenvironment) {
164 messedwith[i] -= multiplier;
165 if (rotxvel[i] || rotx[i]) {
166 if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
167 if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
168 if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
169 if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
170 if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
171 if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
172 if (fabs(rotx[i]) < multiplier * 4)
174 if (fabs(rotxvel[i]) < multiplier * 4)
177 rotx[i] += rotxvel[i] * multiplier * 4;
179 if (rotyvel[i] || roty[i]) {
180 if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
181 if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
182 if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
183 if (roty[i] < 0) rotyvel[i] += multiplier * 4;
184 if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
185 if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
186 if (fabs(roty[i]) < multiplier * 4)
188 if (fabs(rotyvel[i]) < multiplier * 4)
191 roty[i] += rotyvel[i] * multiplier * 4;
194 glRotatef(roty[i] / 6, 1, 0, 0);
197 glRotatef(-rotx[i] / 6, 0, 0, 1);
208 messedwith[i] -= multiplier;
209 if (rotxvel[i] || rotx[i]) {
210 if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
211 if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
212 if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
213 if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
214 if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
215 if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
216 if (fabs(rotx[i]) < multiplier * 4)
218 if (fabs(rotxvel[i]) < multiplier * 4)
221 rotx[i] += rotxvel[i] * multiplier * 4;
223 if (rotyvel[i] || roty[i]) {
224 if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
225 if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
226 if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
227 if (roty[i] < 0) rotyvel[i] += multiplier * 4;
228 if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
229 if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
230 if (fabs(roty[i]) < multiplier * 4)
232 if (fabs(rotyvel[i]) < multiplier * 4)
235 roty[i] += rotyvel[i] * multiplier * 4;
238 glRotatef(roty[i] / 4, 1, 0, 0);
241 glRotatef(-rotx[i] / 4, 0, 0, 1);
254 if (/*detail==2&&*/environment == snowyenvironment) {
255 if (type[i] == treeleavestype) {
256 glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
258 if (type[i] == treetrunktype) {
259 glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
261 if (type[i] == bushtype) {
262 glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
265 if (/*detail==2&&*/environment == grassyenvironment) {
266 if (type[i] == treeleavestype) {
267 glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
269 if (type[i] == treetrunktype) {
270 glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
272 if (type[i] == bushtype) {
273 glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
276 if (/*detail==2&&*/environment == desertenvironment) {
277 if (type[i] == bushtype) {
278 glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
281 glRotatef(yaw[i], 0, 1, 0);
284 glColor4f((1 - shadowed[i]) / 2 + .5, (1 - shadowed[i]) / 2 + .5, (1 - shadowed[i]) / 2 + .5, distance);
287 glAlphaFunc(GL_GREATER, 0.5);
291 glAlphaFunc(GL_GREATER, 0.1);
293 if (type[i] != treetrunktype && type[i] != treeleavestype && type[i] != bushtype && type[i] != rocktype) {
294 glEnable(GL_CULL_FACE);
295 glAlphaFunc(GL_GREATER, 0.0001);
296 model[i].drawdifftex(boxtextureptr);
297 model[i].drawdecals(terrain.shadowtexture, terrain.bloodtexture, terrain.bloodtexture2, terrain.breaktexture);
299 if (type[i] == rocktype) {
300 glEnable(GL_CULL_FACE);
301 glAlphaFunc(GL_GREATER, 0.0001);
302 glColor4f((1 - shadowed[i]) / 2 + light.ambient[0], (1 - shadowed[i]) / 2 + light.ambient[1], (1 - shadowed[i]) / 2 + light.ambient[2], distance);
303 model[i].drawdifftex(rocktextureptr);
304 model[i].drawdecals(terrain.shadowtexture, terrain.bloodtexture, terrain.bloodtexture2, terrain.breaktexture);
306 if (type[i] == treeleavestype) {
307 glDisable(GL_CULL_FACE);
308 glDisable(GL_LIGHTING);
309 terrainlight = terrain.getLighting(position[i].x, position[i].z);
311 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
313 glAlphaFunc(GL_GREATER, 0.2);
318 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance / 3);
319 glAlphaFunc(GL_GREATER, 0);
321 model[i].drawdifftex(treetextureptr);
323 if (type[i] == bushtype) {
324 glDisable(GL_CULL_FACE);
325 glDisable(GL_LIGHTING);
326 terrainlight = terrain.getLighting(position[i].x, position[i].z);
328 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
330 glAlphaFunc(GL_GREATER, 0.2);
335 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance / 3);
336 glAlphaFunc(GL_GREATER, 0);
338 model[i].drawdifftex(bushtextureptr);
340 if (type[i] == treetrunktype) {
341 glEnable(GL_CULL_FACE);
342 terrainlight = terrain.getLighting(position[i].x, position[i].z);
343 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
344 model[i].drawdifftex(treetextureptr);
354 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
355 for (i = 0; i < numobjects; i++) {
356 if (type[i] == treeleavestype || type[i] == bushtype) {
357 moved = DoRotation(model[i].boundingspherecenter, 0, yaw[i], 0);
358 if (frustum.SphereInFrustum(position[i].x + moved.x, position[i].y + moved.y, position[i].z + moved.z, model[i].boundingsphereradius)) {
359 hidden = distsqflat(&viewer, &position[i]) <= playerdist + 3;
362 glMatrixMode(GL_MODELVIEW);
364 glEnable(GL_LIGHTING);
366 glTranslatef(position[i].x, position[i].y, position[i].z);
367 if (type[i] == bushtype) {
368 messedwith[i] -= multiplier;
369 if (rotxvel[i] || rotx[i]) {
370 if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
371 if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
372 if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
373 if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
374 if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
375 if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
376 if (fabs(rotx[i]) < multiplier * 4)
378 if (fabs(rotxvel[i]) < multiplier * 4)
381 rotx[i] += rotxvel[i] * multiplier * 4;
383 if (rotyvel[i] || roty[i]) {
384 if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
385 if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
386 if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
387 if (roty[i] < 0) rotyvel[i] += multiplier * 4;
388 if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
389 if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
390 if (fabs(roty[i]) < multiplier * 4)
392 if (fabs(rotyvel[i]) < multiplier * 4)
395 roty[i] += rotyvel[i] * multiplier * 4;
398 glRotatef(roty[i], 1, 0, 0);
401 glRotatef(-rotx[i], 0, 0, 1);
412 if (type[i] == treetrunktype || type[i] == treeleavestype) {
413 messedwith[i] -= multiplier;
414 if (rotxvel[i] || rotx[i]) {
415 if (rotx[i] > 0) rotxvel[i] -= multiplier * 8 * fabs(rotx[i]);
416 if (rotx[i] < 0) rotxvel[i] += multiplier * 8 * fabs(rotx[i]);
417 if (rotx[i] > 0) rotxvel[i] -= multiplier * 4;
418 if (rotx[i] < 0) rotxvel[i] += multiplier * 4;
419 if (rotxvel[i] > 0) rotxvel[i] -= multiplier * 4;
420 if (rotxvel[i] < 0) rotxvel[i] += multiplier * 4;
421 if (fabs(rotx[i]) < multiplier * 4)
423 if (fabs(rotxvel[i]) < multiplier * 4)
426 rotx[i] += rotxvel[i] * multiplier * 4;
428 if (rotyvel[i] || roty[i]) {
429 if (roty[i] > 0) rotyvel[i] -= multiplier * 8 * fabs(roty[i]);
430 if (roty[i] < 0) rotyvel[i] += multiplier * 8 * fabs(roty[i]);
431 if (roty[i] > 0) rotyvel[i] -= multiplier * 4;
432 if (roty[i] < 0) rotyvel[i] += multiplier * 4;
433 if (rotyvel[i] > 0) rotyvel[i] -= multiplier * 4;
434 if (rotyvel[i] < 0) rotyvel[i] += multiplier * 4;
435 if (fabs(roty[i]) < multiplier * 4)
437 if (fabs(rotyvel[i]) < multiplier * 4)
440 roty[i] += rotyvel[i] * multiplier * 4;
443 glRotatef(roty[i] / 2, 1, 0, 0);
446 glRotatef(-rotx[i] / 2, 0, 0, 1);
457 if (environment == snowyenvironment) {
458 if (type[i] == treeleavestype) {
459 glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
461 if (type[i] == treetrunktype) {
462 glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
464 if (type[i] == bushtype) {
465 glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
468 if (environment == grassyenvironment) {
469 if (type[i] == treeleavestype) {
470 glRotatef((sin(windvar + position[i].x * .3) + .5) * 1.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
472 if (type[i] == treetrunktype) {
473 glRotatef((sin(windvar + position[i].x * .3) + .5)*.5 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
475 if (type[i] == bushtype) {
476 glRotatef((sin(windvar + position[i].x * .3) + .5) * 4 * .5 * (sin(windvar * 2 + position[i].x * .3) + 1) / 2, 1, 0, 0);
479 glRotatef(yaw[i], 0, 1, 0);
480 glColor4f(1, 1, 1, distance);
481 if (type[i] == treeleavestype) {
482 glDisable(GL_CULL_FACE);
483 glDisable(GL_LIGHTING);
484 terrainlight = terrain.getLighting(position[i].x, position[i].z);
487 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3);
488 glAlphaFunc(GL_GREATER, 0);
489 glDisable(GL_ALPHA_TEST);
490 model[i].drawdifftex(treetextureptr);
492 if (type[i] == bushtype) {
493 glDisable(GL_CULL_FACE);
494 glDisable(GL_LIGHTING);
495 terrainlight = terrain.getLighting(position[i].x, position[i].z);
498 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, .3);
499 glAlphaFunc(GL_GREATER, 0);
500 glDisable(GL_ALPHA_TEST);
501 model[i].drawdifftex(bushtextureptr);
508 if (environment == desertenvironment)
509 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0 );
510 glEnable(GL_ALPHA_TEST);
511 SetUpLight(&light, 0);
514 void Objects::DeleteObject(int which)
516 type[numobjects - 1] = 0;
517 yaw[numobjects - 1] = 0;
518 position[numobjects - 1] = 0;
519 scale[numobjects - 1] = 0;
520 friction[numobjects - 1] = 0;
525 void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale)
527 if ((atype != treeleavestype && atype != bushtype) || foliage == 1) {
528 scale[numobjects] = ascale;
529 if (atype == treeleavestype)
530 scale[numobjects] += fabs((float)(Random() % 100) / 900) * ascale;
532 onfire[numobjects] = 0;
533 flamedelay[numobjects] = 0;
534 type[numobjects] = atype;
536 if (atype == firetype)
537 onfire[numobjects] = 1;
539 position[numobjects] = where;
540 if (atype == bushtype)
541 position[numobjects].y = terrain.getHeight(position[numobjects].x, position[numobjects].z) - .3;
542 yaw[numobjects] = ayaw;
544 rotxvel[numobjects] = 0;
545 rotyvel[numobjects] = 0;
546 rotx[numobjects] = 0;
547 roty[numobjects] = 0;
549 if (atype == boxtype) model[numobjects].loaddecal((char *)":Data:Models:Box.solid", 0);
550 if (atype == cooltype) model[numobjects].loaddecal((char *)":Data:Models:Cool.solid", 0);
551 if (atype == walltype) model[numobjects].loaddecal((char *)":Data:Models:Wall.solid", 0);
552 if (atype == tunneltype) model[numobjects].loaddecal((char *)":Data:Models:Tunnel.solid", 0);
553 if (atype == chimneytype) model[numobjects].loaddecal((char *)":Data:Models:Chimney.solid", 0);
554 if (atype == spiketype) model[numobjects].load((char *)":Data:Models:Spike.solid", 0);
555 if (atype == weirdtype) model[numobjects].loaddecal((char *)":Data:Models:Weird.solid", 0);
556 if (atype == rocktype) model[numobjects].loaddecal((char *)":Data:Models:Rock.solid", 0);
557 if (atype == treetrunktype) model[numobjects].load((char *)":Data:Models:Treetrunk.solid", 0);
558 if (atype == treeleavestype) model[numobjects].load((char *)":Data:Models:Leaves.solid", 0);
559 if (atype == bushtype) model[numobjects].load((char *)":Data:Models:Bush.solid", 0);
561 if (atype == boxtype) friction[numobjects] = 1.5;
562 if (atype == cooltype) friction[numobjects] = 1.5;
563 if (atype == walltype) friction[numobjects] = 1.5;
564 if (atype == platformtype) friction[numobjects] = 1.5;
565 if (atype == tunneltype) friction[numobjects] = 1.5;
566 if (atype == chimneytype) friction[numobjects] = 1.5;
567 if (atype == rocktype) friction[numobjects] = .5;
568 if (atype == rocktype && ascale>.5) friction[numobjects] = 1.5;
569 if (atype == weirdtype) friction[numobjects] = 1.5;
570 if (atype == spiketype) friction[numobjects] = .4;
571 if (atype == treetrunktype) friction[numobjects] = .4;
572 if (atype == treeleavestype) friction[numobjects] = 0;
574 if (atype == platformtype) {
575 model[numobjects].loaddecal((char *)":Data:Models:Platform.solid", 0);
576 model[numobjects].Rotate(90, 0, 0);
579 if (type[numobjects] == boxtype || type[numobjects] == cooltype || type[numobjects] == spiketype || type[numobjects] == weirdtype || type[numobjects] == walltype || type[numobjects] == chimneytype || type[numobjects] == tunneltype || type[numobjects] == platformtype) {
580 model[numobjects].ScaleTexCoords(scale[numobjects] * 1.5);
582 if (type[numobjects] == rocktype) {
583 model[numobjects].ScaleTexCoords(scale[numobjects] * 3);
585 model[numobjects].flat = 1;
586 if (atype == treetrunktype || atype == treeleavestype || atype == rocktype) {
587 model[numobjects].flat = 0;
589 model[numobjects].Scale(.3 * scale[numobjects], .3 * scale[numobjects], .3 * scale[numobjects]);
590 model[numobjects].Rotate(90, 1, 1);
591 if (type[numobjects] == rocktype) {
592 model[numobjects].Rotate(ayaw * 5, 1, 1);
594 model[numobjects].CalculateNormals(1);
595 model[numobjects].ScaleNormals(-1, -1, -1);
597 if (atype == treetrunktype && position[numobjects].y < terrain.getHeight(position[numobjects].x, position[numobjects].z) + 1) {
599 terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 2, .4, 0);
602 if (atype == bushtype && position[numobjects].y < terrain.getHeight(position[numobjects].x, position[numobjects].z) + 1) {
604 terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 1, .4, 0);
607 if (atype != treeleavestype && atype != bushtype && atype != firetype)
608 terrain.AddObject(where + DoRotation(model[numobjects].boundingspherecenter, 0, ayaw, 0), model[numobjects].boundingsphereradius, numobjects);
614 void Objects::MakeObject(int atype, XYZ where, float ayaw, float apitch, float ascale)
616 if ((atype != treeleavestype && atype != bushtype) || foliage == 1) {
617 scale[numobjects] = ascale;
618 if (atype == treeleavestype)
619 scale[numobjects] += fabs((float)(Random() % 100) / 900) * ascale;
621 onfire[numobjects] = 0;
622 flamedelay[numobjects] = 0;
623 type[numobjects] = atype;
625 if (atype == firetype)
626 onfire[numobjects] = 1;
628 position[numobjects] = where;
629 if (atype == bushtype)
630 position[numobjects].y = terrain.getHeight(position[numobjects].x, position[numobjects].z) - .3;
631 yaw[numobjects] = ayaw;
632 pitch[numobjects] = apitch;
634 rotxvel[numobjects] = 0;
635 rotyvel[numobjects] = 0;
636 rotx[numobjects] = 0;
637 roty[numobjects] = 0;
639 if (atype == boxtype) model[numobjects].loaddecal((char *)":Data:Models:Box.solid", 0);
640 if (atype == cooltype) model[numobjects].loaddecal((char *)":Data:Models:Cool.solid", 0);
641 if (atype == walltype) model[numobjects].loaddecal((char *)":Data:Models:Wall.solid", 0);
642 if (atype == tunneltype) model[numobjects].loaddecal((char *)":Data:Models:Tunnel.solid", 0);
643 if (atype == chimneytype) model[numobjects].loaddecal((char *)":Data:Models:Chimney.solid", 0);
644 if (atype == spiketype) model[numobjects].load((char *)":Data:Models:Spike.solid", 0);
645 if (atype == weirdtype) model[numobjects].loaddecal((char *)":Data:Models:Weird.solid", 0);
646 if (atype == rocktype) model[numobjects].loaddecal((char *)":Data:Models:Rock.solid", 0);
647 if (atype == treetrunktype) model[numobjects].load((char *)":Data:Models:Treetrunk.solid", 0);
648 if (atype == treeleavestype) model[numobjects].load((char *)":Data:Models:Leaves.solid", 0);
649 if (atype == bushtype) model[numobjects].load((char *)":Data:Models:Bush.solid", 0);
651 if (atype == boxtype) friction[numobjects] = 1.5;
652 if (atype == cooltype) friction[numobjects] = 1.5;
653 if (atype == walltype) friction[numobjects] = 1.5;
654 if (atype == platformtype) friction[numobjects] = 1.5;
655 if (atype == tunneltype) friction[numobjects] = 1.5;
656 if (atype == chimneytype) friction[numobjects] = 1.5;
657 if (atype == rocktype) friction[numobjects] = .5;
658 if (atype == rocktype && ascale>.5) friction[numobjects] = 1.5;
659 if (atype == weirdtype) friction[numobjects] = 1.5;
660 if (atype == spiketype) friction[numobjects] = .4;
661 if (atype == treetrunktype) friction[numobjects] = .4;
662 if (atype == treeleavestype) friction[numobjects] = 0;
664 if (friction[numobjects] == 1.5 && fabs(apitch) > 5)
665 friction[numobjects] = .5;
667 if (atype == platformtype) {
668 model[numobjects].loaddecal((char *)":Data:Models:Platform.solid", 0);
669 model[numobjects].Rotate(90, 0, 0);
672 if (type[numobjects] == boxtype || type[numobjects] == cooltype || type[numobjects] == spiketype || type[numobjects] == weirdtype || type[numobjects] == walltype || type[numobjects] == chimneytype || type[numobjects] == tunneltype || type[numobjects] == platformtype) {
673 model[numobjects].ScaleTexCoords(scale[numobjects] * 1.5);
675 if (type[numobjects] == rocktype) {
676 model[numobjects].ScaleTexCoords(scale[numobjects] * 3);
678 model[numobjects].flat = 1;
679 if (atype == treetrunktype || atype == treeleavestype || atype == rocktype) {
680 model[numobjects].flat = 0;
682 model[numobjects].Scale(.3 * scale[numobjects], .3 * scale[numobjects], .3 * scale[numobjects]);
683 model[numobjects].Rotate(90, 1, 1);
684 model[numobjects].Rotate(apitch, 0, 0);
685 if (type[numobjects] == rocktype) {
686 model[numobjects].Rotate(ayaw * 5, 0, 0);
688 model[numobjects].CalculateNormals(1);
689 model[numobjects].ScaleNormals(-1, -1, -1);
691 if (atype == treetrunktype && position[numobjects].y < terrain.getHeight(position[numobjects].x, position[numobjects].z) + 1) {
693 terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 2, .4, 0);
696 if (atype == bushtype && position[numobjects].y < terrain.getHeight(position[numobjects].x, position[numobjects].z) + 1) {
698 terrain.MakeDecal(shadowdecalpermanent, position[numobjects], 1, .4, 0);
701 if (atype != treeleavestype && atype != bushtype && atype != firetype)
702 terrain.AddObject(where + DoRotation(model[numobjects].boundingspherecenter, 0, ayaw, 0), model[numobjects].boundingsphereradius, numobjects);
708 void Objects::DoStuff()
711 for (int i = 0; i < numobjects; i++) {
712 if (type[i] == firetype)
715 if (type[i] == bushtype)
716 flamedelay[i] -= multiplier * 3;
717 if (type[i] == firetype)
718 flamedelay[i] -= multiplier * 3;
719 if (type[i] == treeleavestype)
720 flamedelay[i] -= multiplier * 4;
721 while (flamedelay[i] < 0 && onfire[i]) {
722 flamedelay[i] += .006;
723 if (type[i] == bushtype || type[i] == firetype) {
724 spawnpoint.x = ((float)(Random() % 100)) / 30 * scale[i];
725 spawnpoint.y = ((float)(Random() % 100) + 60) / 30 * scale[i];
727 spawnpoint = DoRotation(spawnpoint, 0, Random() % 360, 0);
728 spawnpoint += position[i];
729 Sprite::MakeSprite(flamesprite, spawnpoint, spawnpoint * 0, 1, 1, 1, (.6 + (float)abs(Random() % 100) / 200 - .25) * 5 * scale[i], 1);
731 if (type[i] == treeleavestype) {
732 spawnpoint.x = ((float)(Random() % 100)) / 80 * scale[i];
733 spawnpoint.y = ((float)(Random() % 100) + 80) / 12 * scale[i];
735 spawnpoint = DoRotation(spawnpoint, 0, Random() % 360, 0);
736 spawnpoint += position[i];
737 Sprite::MakeSprite(flamesprite, spawnpoint, spawnpoint * 0, 1, 1, 1, (.6 + (float)abs(Random() % 100) / 200 - .25) * 6, 1);
745 void Objects::DoShadows()
748 static XYZ testpoint, testpoint2, terrainpoint, lightloc, col;
749 lightloc = light.location;
753 Normalise(&lightloc);
757 for (i = 0; i < numobjects; i++) {
758 if (type[i] != treeleavestype && type[i] != treetrunktype && type[i] != bushtype && type[i] != firetype) {
759 for (j = 0; j < model[i].vertexNum; j++) {
760 terrainpoint = position[i] + DoRotation(model[i].vertex[j] + model[i].normals[j] * .1, 0, yaw[i], 0);
761 //terrainpoint.y+=model[i].boundingsphereradius;
763 patchx = terrainpoint.x / (terrain.size / subdivision * terrain.scale);
764 patchz = terrainpoint.z / (terrain.size / subdivision * terrain.scale);
765 if (patchx >= 0 && patchz >= 0 && patchx < subdivision && patchz < subdivision)
766 if (terrain.patchobjectnum[patchx][patchz])
767 for (k = 0; k < terrain.patchobjectnum[patchx][patchz]; k++) {
768 l = terrain.patchobjects[patchx][patchz][k];
769 if (type[l] != treetrunktype/*&&l!=i*/) {
770 testpoint = terrainpoint;
771 testpoint2 = terrainpoint + lightloc * 50 * (1 - shadowed[i]);
772 if (model[l].LineCheck(&testpoint, &testpoint2, &col, &position[l], &yaw[l]) != -1) {
773 shadowed[i] = 1 - (findDistance(&terrainpoint, &col) / 50);
777 if (shadowed[i] > 0) {
778 col = model[i].normals[j] - DoRotation(lightloc * shadowed[i], 0, -yaw[i], 0);
780 for (k = 0; k < model[i].TriangleNum; k++) {
781 if (model[i].Triangles[k].vertex[0] == j) {
783 model[i].vArray[l + 2] = col.x;
784 model[i].vArray[l + 3] = col.y;
785 model[i].vArray[l + 4] = col.z;
787 if (model[i].Triangles[k].vertex[1] == j) {
789 model[i].vArray[l + 10] = col.x;
790 model[i].vArray[l + 11] = col.y;
791 model[i].vArray[l + 12] = col.z;
793 if (model[i].Triangles[k].vertex[2] == j) {
795 model[i].vArray[l + 18] = col.x;
796 model[i].vArray[l + 19] = col.y;
797 model[i].vArray[l + 20] = col.z;
813 memset(position, 0, sizeof(position));
814 memset(type, 0, sizeof(type));
815 memset(yaw, 0, sizeof(yaw));
816 memset(pitch, 0, sizeof(pitch));
817 memset(rotx, 0, sizeof(rotx));
818 memset(rotxvel, 0, sizeof(rotxvel));
819 memset(roty, 0, sizeof(roty));
820 memset(rotyvel, 0, sizeof(rotyvel));
821 memset(possible, 0, sizeof(possible));
822 memset(model, 0, sizeof(model));
823 memset(displaymodel, 0, sizeof(displaymodel));
824 memset(friction, 0, sizeof(friction));
825 memset(scale, 0, sizeof(scale));
826 memset(messedwith, 0, sizeof(messedwith));
827 memset(checked, 0, sizeof(checked));
828 memset(shadowed, 0, sizeof(shadowed));
829 memset(occluded, 0, sizeof(occluded));
830 memset(onfire, 0, sizeof(onfire));
831 memset(flamedelay, 0, sizeof(flamedelay));
836 boxtextureptr.destroy();
837 treetextureptr.destroy();
838 bushtextureptr.destroy();
839 rocktextureptr.destroy();