Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
sphereobj.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/sphereobj.cpp $*
26 * *
27 * Org Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Kenny Mitchell *
30 * *
31 * $Modtime:: 06/26/02 4:04p $*
32 * *
33 * $Revision:: 24 $*
34 * *
35 * 06/26/02 KM Matrix name change to avoid MAX conflicts *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * SphereRenderObjClass::SphereRenderObjClass -- Constructor *
39 * SphereRenderObjClass::SphereRenderObjClass -- Constructor - init from a definition *
40 * SphereRenderObjClass::SphereRenderObjClass -- Copy constructor *
41 * SphereRenderObjClass::operator -- assignment operator *
42 * SphereRenderObjClass::Get_Num_Polys -- returns number of polygons *
43 * SphereRenderObjClass::Get_Name -- returns name *
44 * SphereRenderObjClass::Set_Name -- sets the name *
45 * SphereRenderObjClass::render_Sphere -- submits the Sphere to the GERD *
46 * SphereRenderObjClass::vis_render_Sphere -- submits Sphere to the GERD for VIS *
47 * SphereRenderObjClass::SphereRenderObjClass -- constructor *
48 * SphereRenderObjClass::SphereRenderObjClass -- Constructor - init from a definition *
49 * SphereRenderObjClass::SphereRenderObjClass -- copy constructor *
50 * SphereRenderObjClass::SphereRenderObjClass -- Constructor from a wwmath aaSphere *
51 * SphereRenderObjClass::operator -- assignment operator *
52 * SphereRenderObjClass::Clone -- clones the Sphere *
53 * SphereRenderObjClass::Class_ID -- returns the class-id for AASphere's *
54 * SphereRenderObjClass::Render -- render this Sphere *
55 * SphereRenderObjClass::Special_Render -- special render this Sphere (vis) *
56 * SphereRenderObjClass::Set_Transform -- set the transform for this Sphere *
57 * SphereRenderObjClass::Set_Position -- Set the position of this Sphere *
58 * SphereRenderObjClass::update_cached_Sphere -- update the world-space version of this Spher*
59 * SphereRenderObjClass::Cast_Ray -- cast a ray against this Sphere *
60 * SphereRenderObjClass::Cast_AASphere -- cast an AASphere against this Sphere *
61 * SphereRenderObjClass::Cast_OBSphere -- cast an OBSphere against this Sphere *
62 * SphereRenderObjClass::Intersect_AASphere -- intersect this Sphere with an AASphere *
63 * SphereRenderObjClass::Intersect_OBSphere -- Intersect this Sphere with an OBSphere *
64 * SphereRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the object-space bounding sp*
65 * SphereRenderObjClass::Get_Obj_Space_Bounding_Sphere -- returns the obj-space bounding Sphe*
66 * SphereRenderObjClass::Scale -- scales sphere uniformly. *
67 * SphereRenderObjClass::Scale -- scales sphere non-uniformly. *
68 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
69
70
71#include "sphereobj.h"
72#include "w3d_util.h"
73#include "wwdebug.h"
74#include "vertmaterial.h"
75#include "ww3d.h"
76#include "chunkio.h"
77#include "rinfo.h"
78#include "coltest.h"
79#include "bound.h"
80#include "inttest.h"
81#include "predlod.h"
82#include "matrix3.h"
83#include "wwmath.h"
84#include "assetmgr.h"
85#include "wwstring.h"
86#include "camera.h"
87#include "statistics.h"
88#include "dx8wrapper.h"
89#include "dx8vertexbuffer.h"
90#include "dx8indexbuffer.h"
91#include "sortingrenderer.h"
92#include "visrasterizer.h"
93
94static bool Sphere_Array_Valid = false;
95
97float SphereLODCosts[SPHERE_NUM_LOD + 1]; // SPHERE_NUM_LOD doesn't include the null LOD
98
99
100/*
101** SphereRenderObjClass Implementation
102*/
103
104/***********************************************************************************************
105 * SphereRenderObjClass::SphereRenderObjClass -- Constructor *
106 * *
107 * INPUT: *
108 * *
109 * OUTPUT: *
110 * *
111 * WARNINGS: *
112 * *
113 * HISTORY: *
114 * 1/19/00 gth : Created. *
115 *=============================================================================================*/
117 : anim_time (0.0F),
119 LODBias(1.0f),
120 CurrentLOD(SPHERE_NUM_LOD), // SPHERE_NUM_LOD does not include the null LOD
121 AnimDuration (0.0F),
124 CurrentColor(0.75f, 0.75f, 0.75F),
125 CurrentAlpha(1.0f),
126 CurrentScale(1.0f, 1.0f, 1.0f),
129 ObjSpaceCenter (0, 0, 0),
130 ObjSpaceExtent (1, 1, 1)
131{
133
134 Orientation.Make_Identity();
135 memset(Name,0,sizeof(Name));
136
137 Init_Material ();
138
139 // So that the object is ready for use after construction, we will
140 // complete its initialization by initializing its value array
141 // according to a screen area of 1.
143}
144
145
146/***********************************************************************************************
147 * SphereRenderObjClass::SphereRenderObjClass -- Constructor - init from a definition *
148 * *
149 * INPUT: *
150 * *
151 * OUTPUT: *
152 * *
153 * WARNINGS: *
154 * *
155 * HISTORY: *
156 * 1/19/00 gth : Created. *
157 *=============================================================================================*/
159 : anim_time (0.0F),
161 LODBias(1.0f),
162 CurrentLOD(SPHERE_NUM_LOD), // SPHERE_NUM_LOD does not include the null LOD
163 AnimDuration (0.0F),
166 CurrentColor(0.75f, 0.75f, 0.75F),
167 CurrentAlpha(1.0f),
168 CurrentScale(1.0f, 1.0f, 1.0f),
171 ObjSpaceCenter (0, 0, 0),
172 ObjSpaceExtent (1, 1, 1)
173{
175 Init_Material ();
176 Orientation.Make_Identity();
177
178 //
179 // Initialize from the defintion
180 //
181 Set_Name(def.Name);
183 Vector3 (def.Extent.X, def.Extent.Y, def.Extent.Z));
184
185 if (def.TextureName[0] != 0) {
187 }
188
189 // So that the object is ready for use after construction, we will
190 // complete its initialization by initializing its value array
191 // according to a screen area of 1.
193}
194
195
196/***********************************************************************************************
197 * SphereRenderObjClass::SphereRenderObjClass -- Copy constructor *
198 * *
199 * INPUT: *
200 * *
201 * OUTPUT: *
202 * *
203 * WARNINGS: *
204 * *
205 * HISTORY: *
206 * 1/19/00 gth : Created. *
207 *=============================================================================================*/
209 : anim_time (0.0F),
211 LODBias(1.0f),
212 CurrentLOD(SPHERE_NUM_LOD), // SPHERE_NUM_LOD does not include the null LOD
213 AnimDuration (0.0F),
216 CurrentColor(0.75f, 0.75f, 0.75F),
217 CurrentAlpha(1.0f),
218 CurrentScale(1.0f, 1.0f, 1.0f),
221 ObjSpaceCenter (0, 0, 0),
222 ObjSpaceExtent (1, 1, 1)
223{
225 Init_Material ();
226 Orientation.Make_Identity();
227
228 *this = src;
229
230 // So that the object is ready for use after construction, we will
231 // complete its initialization by initializing its value array
232 // according to a screen area of 1.
234}
235
240
241/***********************************************************************************************
242 * SphereRenderObjClass::operator -- assignment operator *
243 * *
244 * INPUT: *
245 * *
246 * OUTPUT: *
247 * *
248 * WARNINGS: *
249 * *
250 * HISTORY: *
251 * 1/19/00 gth : Created. *
252 *=============================================================================================*/
254{
255 if (this != &that) {
257 Set_Name(that.Get_Name());
262 Flags = that.Flags;
265 CachedBox = that.CachedBox;
266 anim_time = that.anim_time;
274
276 }
277
278 return *this;
279}
280
281
282/***********************************************************************************************
283 * SphereRenderObjClass::Generate_Shared_Mesh_Arrays -- Generates mesh LOD arrays. *
284 * *
285 * INPUT: *
286 * *
287 * OUTPUT: *
288 * *
289 * WARNINGS: *
290 * *
291 * HISTORY: *
292 * 03/08/00 pds : Created. *
293 *=============================================================================================*/
295{
296 // Generate shared Mesh Arrays
297 if (!Sphere_Array_Valid) {
298
299 float size = SPHERE_LOWEST_LOD;
300 float step = (SPHERE_HIGHEST_LOD - SPHERE_LOWEST_LOD);
301 step /= SPHERE_NUM_LOD;
302
303 // For NULL LOD set Cost to a small nonzero amount to avoid divisions by zero.
304 SphereLODCosts[0] = 0.000001f;
305 for(int i=0; i < SPHERE_NUM_LOD; i++) {
306
307 SphereMeshArray[i].Generate(1.0f, size, size);
308 SphereLODCosts[i + 1] = SphereMeshArray[i].Get_Num_Polys();
309
310 size+=step;
311
312 SphereMeshArray[i].Set_Alpha_Vector( alphavector, false, false );
313
314 }
315
316 Sphere_Array_Valid = true;
317 }
318
319 return ;
320}
321
322
323// This is used both by Prepare_LOD and Calculate_Cost_Value_Arrays.
324void SphereRenderObjClass::calculate_value_array(float screen_area, float *values) const
325{
326 values[0] = AT_MIN_LOD;
327 for (int lod = 1; lod <= SPHERE_NUM_LOD; lod++) {
328 float polycount = SphereLODCosts[lod];
329 float benefit_factor = 1 - (0.5f / (polycount * polycount));
330 values[lod] = (benefit_factor * screen_area * LODBias) / polycount;
331 }
332 values[SPHERE_NUM_LOD + 1] = AT_MAX_LOD; // Post-inc value will flag max LOD.
333}
334
335
336/***********************************************************************************************
337 * SphereRenderObjClass::Init_Material -- Sets up the material and default shader for the sphere.*
338 * *
339 * INPUT: *
340 * *
341 * OUTPUT: *
342 * *
343 * WARNINGS: *
344 * *
345 * HISTORY: *
346 * 03/08/00 pds : Created. *
347 *=============================================================================================*/
349{
351
353 SphereMaterial->Set_Ambient(0,0,0);
354 SphereMaterial->Set_Diffuse(0,0,0);
355 SphereMaterial->Set_Specular(0,0,0);
356 SphereMaterial->Set_Emissive(1,1,1);
357 SphereMaterial->Set_Opacity(0.25f);
358 SphereMaterial->Set_Shininess(0.0f);
359 SphereMaterial->Set_Lighting(true);
360
361 // Texturing, zbuffer, primary gradient, alpha blending
363
364 // (gth) Looks like sphere's were coded with backwards normals! Quick fix (though expensive)
365 // is to turn off backface culling... ug...
367
368} // Init_Material
369
370
371/***********************************************************************************************
372 * SphereRenderObjClass::Get_Num_Polys -- returns number of polygons *
373 * *
374 * INPUT: *
375 * *
376 * OUTPUT: *
377 * *
378 * WARNINGS: *
379 * *
380 * HISTORY: *
381 * 1/19/00 gth : Created. *
382 *=============================================================================================*/
384{
386}
387
388
389/***********************************************************************************************
390 * SphereRenderObjClass::Set_Texture *
391 * *
392 * INPUT: *
393 * *
394 * OUTPUT: *
395 * *
396 * WARNINGS: *
397 * *
398 * HISTORY: *
399 * 1/19/00 gth : Created. *
400 *=============================================================================================*/
405
406
407/***********************************************************************************************
408 * SphereRenderObjClass::Get_Name -- returns name *
409 * *
410 * INPUT: *
411 * *
412 * OUTPUT: *
413 * *
414 * WARNINGS: *
415 * *
416 * HISTORY: *
417 * 1/19/00 gth : Created. *
418 *=============================================================================================*/
419const char * SphereRenderObjClass::Get_Name(void) const
420{
421 return Name;
422}
423
424
425/***********************************************************************************************
426 * SphereRenderObjClass::Set_Name -- sets the name *
427 * *
428 * INPUT: *
429 * *
430 * OUTPUT: *
431 * *
432 * WARNINGS: *
433 * *
434 * HISTORY: *
435 * 1/19/00 gth : Created. *
436 *=============================================================================================*/
437void SphereRenderObjClass::Set_Name(const char * name)
438{
439 WWASSERT(name != NULL);
440 WWASSERT(strlen(name) < 2*W3D_NAME_LEN);
441 strcpy(Name,name);
442}
443
444
445/***********************************************************************************************
446 * SphereRenderObjClass::render_sphere *
447 * *
448 * INPUT: *
449 * *
450 * OUTPUT: *
451 * *
452 * WARNINGS: *
453 * *
454 * HISTORY: *
455 * 3/01/00 jga : Created. *
456 * 2/19/01 HY : upgraded to DX8 *
457 *=============================================================================================*/
459{
460 // Should never get here with NULL LOD
461 if (CurrentLOD == 0) {
462 WWASSERT(0);
463 return;
464 }
465
467
468 if (SphereTexture) {
470 } else {
472 }
476
477 // Enable sorting if the primitive is translucent, alpha testing is not enabled, and sorting is enabled globally.
478 const bool sort = (SphereShader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO) && (SphereShader.Get_Alpha_Test() == ShaderClass::ALPHATEST_DISABLE) && (WW3D::Is_Sorting_Enabled());
479 const unsigned int buffer_type = sort ? BUFFER_TYPE_DYNAMIC_SORTING : BUFFER_TYPE_DYNAMIC_DX8;
480
481 DynamicVBAccessClass vb(buffer_type, dynamic_fvf_type, mesh.Vertex_ct);
482 {
485
486 for (int i=0; i<mesh.Vertex_ct; i++)
487 {
488 vb->x = mesh.vtx[i].X;
489 vb->y = mesh.vtx[i].Y;
490 vb->z = mesh.vtx[i].Z;
491
492 vb->nx = mesh.vtx_normal[i].X; // may not need this!
493 vb->ny = mesh.vtx_normal[i].Y;
494 vb->nz = mesh.vtx_normal[i].Z;
495
496 if (Flags & USE_ALPHA_VECTOR) {
497 vb->diffuse = DX8Wrapper::Convert_Color(mesh.dcg[i]);
498 } else {
499 vb->diffuse = 0xFFFFFFFF; // TODO could combine the material color with this and turn off lighting
500 }
501
502 if (SphereTexture) {
503 vb->u1 = mesh.vtx_uv[i].X;
504 vb->v1 = mesh.vtx_uv[i].Y;
505 }
506 vb++;
507 }
508 }
509
510 DynamicIBAccessClass ib(buffer_type, mesh.face_ct*3);
511 {
513 unsigned short *mem=Lock.Get_Index_Array();
514 for (int i=0; i<mesh.face_ct; i++)
515 {
516 mem[3*i]=mesh.tri_poly[i].I;
517 mem[3*i+1]=mesh.tri_poly[i].J;
518 mem[3*i+2]=mesh.tri_poly[i].K;
519 }
520 }
521
524
525 if (sort) {
526 SortingRendererClass::Insert_Triangles(Get_Bounding_Sphere(), 0, mesh.face_ct, 0, mesh.Vertex_ct);
527 } else {
528 DX8Wrapper::Draw_Triangles(0,mesh.face_ct,0,mesh.Vertex_ct);
529 }
530
531} // render_sphere
532
533
534/***********************************************************************************************
535 * SphereRenderObjClass::vis_render_sphere -- submits box to the GERD for VIS *
536 * *
537 * this renders the sphere with the specified VIS-ID. *
538 * *
539 * INPUT: *
540 * *
541 * OUTPUT: *
542 * *
543 * WARNINGS: *
544 * *
545 * HISTORY: *
546 * 1/19/00 gth : Created. *
547 *=============================================================================================*/
549{
550} // vis_render_sphere
551
552
553/***********************************************************************************************
554 * SphereRenderObjClass::Clone -- clones the box *
555 * *
556 * INPUT: *
557 * *
558 * OUTPUT: *
559 * *
560 * WARNINGS: *
561 * *
562 * HISTORY: *
563 * 1/19/00 gth : Created. *
564 *=============================================================================================*/
569
570
571/***********************************************************************************************
572 * SphereRenderObjClass::Class_ID -- returns the class-id for sphere's *
573 * *
574 * INPUT: *
575 * *
576 * OUTPUT: *
577 * *
578 * WARNINGS: *
579 * *
580 * HISTORY: *
581 * 1/19/00 gth : Created. *
582 *=============================================================================================*/
587
588
589/***********************************************************************************************
590 * SphereRenderObjClass::Render -- render this box *
591 * *
592 * INPUT: *
593 * *
594 * OUTPUT: *
595 * *
596 * WARNINGS: *
597 * *
598 * HISTORY: *
599 * 1/19/00 gth : Created. *
600 *=============================================================================================*/
602{
603 // NULL LOD
604 if (CurrentLOD == 0) return;
605
606 if (Is_Not_Hidden_At_All() == false) {
607 return;
608 }
609
610 unsigned int sort_level = SORT_LEVEL_NONE;
611
613 sort_level = SphereShader.Guess_Sort_Level();
614 }
615
617
618 WW3D::Add_To_Static_Sort_List(this, sort_level);
619
620 } else {
621
622 // Process texture reductions:
623// if (SphereTexture) SphereTexture->Process_Reduction();
624
625 Matrix3D temp = Transform;
626
627 // Do Time Based Animation
628 animate();
629
630 // Scale
631
632 Vector3 real_scale;
633 real_scale.X = ObjSpaceExtent.X * CurrentScale.X;
634 real_scale.Y = ObjSpaceExtent.Y * CurrentScale.Y;
635 real_scale.Z = ObjSpaceExtent.Z * CurrentScale.Z;
636 temp.Scale(real_scale);
637
638 //
639 // Configure the alpha
640 //
641 bool is_additive = (SphereShader.Get_Dst_Blend_Func () == ShaderClass::DSTBLEND_ONE);
642 if (is_additive) {
643 SphereMaterial->Set_Emissive (CurrentAlpha * CurrentColor);
644 } else {
645 SphereMaterial->Set_Opacity (CurrentAlpha);
646 SphereMaterial->Set_Emissive (CurrentColor);
647 }
648
649 // If using Alpha Vector, check to see if it needs updated
650 if (Flags & USE_ALPHA_VECTOR) {
651
652 bool use_inverse = false;
653
654 if (Flags & USE_INVERSE_ALPHA) {
655 use_inverse = true;
656 }
657
658 SphereMeshArray[CurrentLOD - 1].Set_Alpha_Vector( CurrentVector, use_inverse, is_additive );
659 }
660
661 // Camera Align
662 if (Flags & USE_CAMERA_ALIGN) {
663 Matrix4x4 view,ident(true);
664 DX8Wrapper::Get_Transform(D3DTS_VIEW,view);
665
666 Vector4 wpos(Transform[0][3],Transform[1][3],Transform[2][3],1);
667 Vector4 cpos;
668
669 Matrix4x4::Transform_Vector(view,wpos,&cpos);
670 Matrix3D tm(0.0f, 1.0f, 0.0f, cpos.X,
671 0.0f, 0.0f, 1.0f, cpos.Y,
672 1.0f, 0.0f, 0.0f, cpos.Z);
673
674 tm.Scale(real_scale);
675 DX8Wrapper::Set_Transform(D3DTS_WORLD,ident);
676 DX8Wrapper::Set_Transform(D3DTS_VIEW,tm);
678 DX8Wrapper::Set_Transform(D3DTS_VIEW,view);
679 } else {
680 DX8Wrapper::Set_Transform(D3DTS_WORLD,temp);
682 }
683 }
684}
685
686
687/***********************************************************************************************
688 * SphereRenderObjClass::Special_Render -- special render this box (vis) *
689 * *
690 * INPUT: *
691 * *
692 * OUTPUT: *
693 * *
694 * WARNINGS: *
695 * *
696 * HISTORY: *
697 * 1/19/00 gth : Created. *
698 *=============================================================================================*/
700{
701 Matrix3D temp(1);
702 temp.Translate(Transform.Get_Translation());
703
705 WWASSERT(rinfo.VisRasterizer != NULL);
708 }
709}
710
711
712/***********************************************************************************************
713 * SphereRenderObjClass::Set_Transform -- set the transform for this box *
714 * *
715 * INPUT: *
716 * *
717 * OUTPUT: *
718 * *
719 * WARNINGS: *
720 * *
721 * HISTORY: *
722 * 1/19/00 gth : Created. *
723 *=============================================================================================*/
729
730
731/***********************************************************************************************
732 * SphereRenderObjClass::Set_Position -- Set the position of this box *
733 * *
734 * INPUT: *
735 * *
736 * OUTPUT: *
737 * *
738 * WARNINGS: *
739 * *
740 * HISTORY: *
741 * 1/19/00 gth : Created. *
742 *=============================================================================================*/
748
749
750/***********************************************************************************************
751 * SphereRenderObjClass::update_cached_box -- update the world-space version of this box *
752 * *
753 * INPUT: *
754 * *
755 * OUTPUT: *
756 * *
757 * WARNINGS: *
758 * *
759 * HISTORY: *
760 * 1/19/00 gth : Created. *
761 *=============================================================================================*/
763{
764 CachedBox.Center = Transform.Get_Translation() + ObjSpaceCenter;
765 CachedBox.Extent = ObjSpaceExtent;
766}
767
768
769/***********************************************************************************************
770 * SphereRenderObjClass::Get_Obj_Space_Bounding_Sphere -- return the object-space bounding sphe *
771 * *
772 * INPUT: *
773 * *
774 * OUTPUT: *
775 * *
776 * WARNINGS: *
777 * *
778 * HISTORY: *
779 * 1/19/00 gth : Created. *
780 *=============================================================================================*/
785
786
787/***********************************************************************************************
788 * SphereRenderObjClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
789 * *
790 * INPUT: *
791 * *
792 * OUTPUT: *
793 * *
794 * WARNINGS: *
795 * *
796 * HISTORY: *
797 * 1/19/00 gth : Created. *
798 *=============================================================================================*/
803
804
806{
807 if (Is_Not_Hidden_At_All() == false) {
808 return;
809 }
810
812
814}
815
820
822{
823 if (CurrentLOD > 0) CurrentLOD--;
824}
825
827{
828 return Get_Num_Polys(); // Currently cost == polys
829}
830
832{
833 return Value[CurrentLOD];
834}
835
837{
838 return Value[CurrentLOD + 1];
839}
840
842{
843 CurrentLOD = Bound(lod, 0, SPHERE_NUM_LOD); // SPHERE_NUM_LOD doesn't include the null LOD
844}
845
847{
848 return CurrentLOD;
849}
850
852{
853 return SPHERE_NUM_LOD + 1; // SPHERE_NUM_LOD doesn't include the null LOD
854}
855
856int SphereRenderObjClass::Calculate_Cost_Value_Arrays(float screen_area, float *values, float *costs) const
857{
858 calculate_value_array(screen_area, values);
859 for (int lod = 0; lod <= SPHERE_NUM_LOD; lod++) {
860 costs[lod] = SphereLODCosts[lod];
861 }
862
863 // We currently don't support max screen size or minimum LOD clamping for sphere objects
864 return 0;
865}
866
867
868/***********************************************************************************************
869 * SphereRenderObjClass::Scale -- scales sphere uniformly. *
870 * *
871 * INPUT: *
872 * *
873 * OUTPUT: *
874 * *
875 * WARNINGS: *
876 * *
877 * HISTORY: *
878 * 7/01/02 NH : Created. *
879 *=============================================================================================*/
881{
882 if (scale == 1.0f) return;
883
884 // Scale default value
886
887 // Loop over all keys in scale channel and scale values.
888 int i;
889 int count = ScaleChannel.Get_Key_Count();
890 for (i = 0; i < count; i++) {
892 ScaleChannel.Set_Key_Value(i, key.Get_Value() * scale);
893 }
894}
895
896
897/***********************************************************************************************
898 * SphereRenderObjClass::Scale -- scales sphere non-uniformly. *
899 * *
900 * INPUT: *
901 * *
902 * OUTPUT: *
903 * *
904 * WARNINGS: *
905 * *
906 * HISTORY: *
907 * 7/01/02 NH : Created. *
908 *=============================================================================================*/
909void SphereRenderObjClass::Scale(float scalex, float scaley, float scalez)
910{
911 // Scale default value
912 CurrentScale.X *= scalex;
913 CurrentScale.Y *= scaley;
914 CurrentScale.Z *= scalez;
915
916 // Loop over all keys in scale channel and scale values.
917 int i;
918 int count = ScaleChannel.Get_Key_Count();
919 for (i = 0; i < count; i++) {
921 Vector3 key_val = key.Get_Value();
922 key_val.X *= scalex;
923 key_val.Y *= scaley;
924 key_val.Z *= scalez;
925 ScaleChannel.Set_Key_Value(i, key_val);
926 }
927}
928
929
930
931/***********************************************************************************************
932 * SphereRenderObjClass::Update_Cached_Bounding_Volumes -- Updates world-space bounding volumes *
933 * *
934 * INPUT: *
935 * *
936 * OUTPUT: *
937 * *
938 * WARNINGS: *
939 * *
940 * HISTORY: *
941 * 1/19/00 gth : Created. *
942 *=============================================================================================*/
954
955
956/***********************************************************************************************
957 * SphereRenderObjClass::Get_Default_Color - get the default (or first frame) value *
958 * *
959 * INPUT: *
960 * *
961 * OUTPUT: *
962 * *
963 * WARNINGS: *
964 * *
965 * HISTORY: *
966 * 3/13/2000 pds : Created. *
967 *=============================================================================================*/
969{
971
972 if (ColorChannel.Get_Key_Count () > 0) {
973 value = ColorChannel.Get_Key (0).Get_Value ();
974 } else {
976 }
977
978 return value;
979}
980
981
982/***********************************************************************************************
983 * SphereRenderObjClass::Get_Default_Alpha - get the default (or first frame) value *
984 * *
985 * INPUT: *
986 * *
987 * OUTPUT: *
988 * *
989 * WARNINGS: *
990 * *
991 * HISTORY: *
992 * 3/13/2000 pds : Created. *
993 *=============================================================================================*/
995{
996 float value;
997
998 if (AlphaChannel.Get_Key_Count () > 0) {
999 value = AlphaChannel.Get_Key (0).Get_Value ();
1000 } else {
1002 }
1003
1004 return value;
1005}
1006
1007
1008/***********************************************************************************************
1009 * SphereRenderObjClass::Get_Default_Scale - get the default (or first frame) value *
1010 * *
1011 * INPUT: *
1012 * *
1013 * OUTPUT: *
1014 * *
1015 * WARNINGS: *
1016 * *
1017 * HISTORY: *
1018 * 3/13/2000 pds : Created. *
1019 *=============================================================================================*/
1021{
1022 Vector3 value;
1023
1024 if (ScaleChannel.Get_Key_Count () > 0) {
1025 value = ScaleChannel.Get_Key (0).Get_Value ();
1026 } else {
1028 }
1029
1030 return value;
1031}
1032
1033
1034/***********************************************************************************************
1035 * SphereRenderObjClass::Get_Default_Vector - get the default (or first frame) value *
1036 * *
1037 * INPUT: *
1038 * *
1039 * OUTPUT: *
1040 * *
1041 * WARNINGS: *
1042 * *
1043 * HISTORY: *
1044 * 3/13/2000 pds : Created. *
1045 *=============================================================================================*/
1047{
1049
1050 if (VectorChannel.Get_Key_Count () > 0) {
1051 value = VectorChannel.Get_Key (0).Get_Value ();
1052 } else {
1054 }
1055
1056 return value;
1057}
1058
1059
1060/***********************************************************************************************
1061 * SphereRenderObjClass::Update_On_Visibilty -- Either starts or stops the animation based on visibility*
1062 * *
1063 * INPUT: *
1064 * *
1065 * OUTPUT: *
1066 * *
1067 * WARNINGS: *
1068 * *
1069 * HISTORY: *
1070 * 4/04/00 pds : Created. *
1071 *=============================================================================================*/
1073{
1074 // Simply start or stop the animation based on
1075 // the visibility state of the primitive.
1076 if (Is_Not_Hidden_At_All () && Is_Animating () == false) {
1077 Start_Animating ();
1078 } else if ((Is_Not_Hidden_At_All () == false) && Is_Animating ()) {
1079 Stop_Animating ();
1080 }
1081
1082 return ;
1083}
1084
1085
1086/***********************************************************************************************
1087 * SphereRenderObjClass::animate -- Update Current Display state *
1088 * *
1089 * INPUT: *
1090 * *
1091 * OUTPUT: *
1092 * *
1093 * WARNINGS: *
1094 * *
1095 * HISTORY: *
1096 * 3/07/00 jga : Created. *
1097 *=============================================================================================*/
1099{
1100 if (Is_Animating ()) {
1101
1102 if ( ColorChannel.Get_Key_Count () > 0 ||
1103 AlphaChannel.Get_Key_Count () > 0 ||
1104 ScaleChannel.Get_Key_Count () > 0 ||
1105 VectorChannel.Get_Key_Count () > 0)
1106 {
1107 //
1108 // Convert from milliseconds to seconds and normalize the time
1109 //
1110 if (AnimDuration > 0) {
1111 float frametime = WW3D::Get_Frame_Time();
1112 frametime = (frametime * 0.001F) / AnimDuration;
1113 anim_time += frametime;
1114 } else {
1115 anim_time = 1.0F;
1116 }
1117 WWASSERT (anim_time >= 0.0F);
1118
1119 if ((Flags & USE_ANIMATION_LOOP) && anim_time > 1.0F) {
1120 anim_time -= 1.0F;
1121 }
1122
1123 if (ColorChannel.Get_Key_Count () > 0) {
1124 CurrentColor = ColorChannel.Evaluate (anim_time);
1125 }
1126
1127 if (AlphaChannel.Get_Key_Count () > 0) {
1128 CurrentAlpha = AlphaChannel.Evaluate (anim_time);
1129 }
1130
1131 if (ScaleChannel.Get_Key_Count () > 0) {
1132 CurrentScale = ScaleChannel.Evaluate (anim_time);
1134 }
1135
1136 if (VectorChannel.Get_Key_Count () > 0) {
1138 }
1139 }
1140 }
1141
1142 return ;
1143
1144} // animate
1145
1146
1147/*
1148** SphereLoaderClass Implementation
1149*/
1151{
1153 prototype->Load (cload);
1154 return prototype;
1155}
1156
1157/*
1158** SpherePrototypeClass Implementation
1159*/
1161{
1162 ::memset (&Definition, 0, sizeof (Definition));
1163 return ;
1164}
1165
1167{
1168 ::memset (&Definition, 0, sizeof (Definition));
1169 ::strcpy (Definition.Name, sphere->Get_Name ());
1170
1171 Definition.DefaultAlpha = sphere->Get_Default_Alpha ();
1172 Definition.AnimDuration = sphere->AnimDuration;
1173 Definition.Attributes = sphere->Get_Flags ();
1174 Definition.DefaultVector = sphere->Get_Default_Vector ();
1175
1176 Vector3 def_color = sphere->Get_Default_Color ();
1177 Vector3 def_scale = sphere->Get_Default_Scale ();
1178 W3dUtilityClass::Convert_Vector (def_color, &Definition.DefaultColor);
1179 W3dUtilityClass::Convert_Vector (def_scale, &Definition.DefaultScale);
1180
1181 W3dUtilityClass::Convert_Vector (sphere->Get_Box ().Center, &Definition.Center);
1182 W3dUtilityClass::Convert_Vector (sphere->Get_Box ().Extent, &Definition.Extent);
1183 W3dUtilityClass::Convert_Shader (sphere->SphereShader, &Definition.Shader);
1184
1185 //
1186 // Determine the texture name for this sphere
1187 //
1188 if (sphere->SphereTexture != NULL) {
1189 StringClass name = sphere->SphereTexture->Get_Full_Path();
1190 const char *filename = ::strrchr (name, '\\');
1191 if (filename != NULL) {
1192 filename ++;
1193 } else {
1194 filename = name;
1195 }
1196
1197 ::strcpy (Definition.TextureName, filename);
1198
1199 }
1200
1201 //
1202 // Save the animateable channels
1203 //
1204 ColorChannel = sphere->Peek_Color_Channel ();
1205 AlphaChannel = sphere->Peek_Alpha_Channel ();
1206 ScaleChannel = sphere->Peek_Scale_Channel ();
1207 VectorChannel = sphere->Peek_Vector_Channel ();
1208 return ;
1209}
1210
1215
1216enum
1217{
1223};
1224
1226{
1227 ColorChannel.Reset ();
1228 AlphaChannel.Reset ();
1229 ScaleChannel.Reset ();
1230 VectorChannel.Reset ();
1231
1232 while (cload.Open_Chunk ()) {
1233 switch (cload.Cur_Chunk_ID ()) {
1234
1235 case CHUNKID_SPHERE_DEF:
1236 cload.Read (&Definition, sizeof (Definition));
1237 break;
1238
1240 ColorChannel.Load (cload);
1241 break;
1242
1244 AlphaChannel.Load (cload);
1245 break;
1246
1248 ScaleChannel.Load (cload);
1249 break;
1250
1252 VectorChannel.Load (cload);
1253 break;
1254 }
1255
1256 cload.Close_Chunk ();
1257 }
1258
1259 return true;
1260}
1261
1263{
1265
1267 csave.Write (&Definition, sizeof (Definition));
1268 csave.End_Chunk ();
1269
1270 if (ColorChannel.Get_Key_Count () > 0) {
1272 ColorChannel.Save (csave);
1273 csave.End_Chunk ();
1274 }
1275
1276 if (AlphaChannel.Get_Key_Count () > 0) {
1278 AlphaChannel.Save (csave);
1279 csave.End_Chunk ();
1280 }
1281
1282
1283 if (ScaleChannel.Get_Key_Count () > 0) {
1285 ScaleChannel.Save (csave);
1286 csave.End_Chunk ();
1287 }
1288
1289 if (VectorChannel.Get_Key_Count () > 0) {
1291 VectorChannel.Save (csave);
1292 csave.End_Chunk ();
1293 }
1294
1295 csave.End_Chunk ();
1296 return true;
1297}
1298
1299const char * SpherePrototypeClass::Get_Name(void) const
1300{
1301 return Definition.Name;
1302}
1303
1308
1310{
1311 //
1312 // Create the new render object
1313 //
1314 SphereRenderObjClass *sphere = W3DNEW SphereRenderObjClass (Definition);
1315
1316 //
1317 // Configure the sphere
1318 //
1319 W3dUtilityClass::Convert_Shader (Definition.Shader, &sphere->SphereShader);
1320 if (WW3DAssetManager::Get_Instance()->Get_Activate_Fog_On_Load()) {
1321 sphere->SphereShader.Enable_Fog ("SpherePrototypeClass");
1322 }
1323 W3dUtilityClass::Convert_Vector (Definition.DefaultColor, &sphere->CurrentColor);
1324 W3dUtilityClass::Convert_Vector (Definition.DefaultScale, &sphere->CurrentScale);
1325 sphere->CurrentVector = Definition.DefaultVector;
1326 sphere->Set_Animation_Duration (Definition.AnimDuration);
1327 sphere->CurrentAlpha = Definition.DefaultAlpha;
1328 sphere->Set_Flags (Definition.Attributes);
1329
1330 //
1331 // Initialize the render object with the keyframe arrays
1332 //
1333 sphere->Set_Color_Channel (ColorChannel);
1334 sphere->Set_Alpha_Channel (AlphaChannel);
1335 sphere->Set_Scale_Channel (ScaleChannel);
1336 sphere->Set_Vector_Channel (VectorChannel);
1337 return sphere;
1338}
1339
1340/*
1341** Global instance of the box loader
1342*/
1344
1345
1346//
1347// Vertices are ordered as such
1348// North Pole, stack 1, stack 2, stack x..., SouthPole
1349//
1350/***********************************************************************************************
1351 * SphereMeshClass::SphereMeshClass -- Constructor for SphereMesh Geometry *
1352 * *
1353 * INPUT: *
1354 * *
1355 * OUTPUT: *
1356 * *
1357 * WARNINGS: *
1358 * *
1359 * HISTORY: *
1360 * 3/07/00 jga : Created. *
1361 *=============================================================================================*/
1362SphereMeshClass::SphereMeshClass(float radius, int slices, int stacks):
1363Radius(radius),
1364Slices(slices),
1365Stacks(stacks),
1366Vertex_ct(0),
1367vtx(NULL),
1368vtx_normal(NULL),
1369vtx_uv(NULL),
1370strip_ct(0),
1371strip_size(0),
1372strips(NULL),
1373fan_ct(0),
1374fan_size(0),
1375fans(NULL),
1376face_ct(0),
1377tri_poly(NULL),
1378inverse_alpha(false)
1379{
1380 // compute # of vertices
1381 // 1st 2 vertices, represent, north, and south pole (Y - axis)
1382
1383 Generate(radius, slices, stacks);
1384
1385} // SphereMesh Constructor
1386
1387/***********************************************************************************************
1388 * SphereMeshClass::SphereMeshClass -- Constructor for SphereMesh Geometry *
1389 * *
1390 * INPUT: *
1391 * *
1392 * OUTPUT: *
1393 * *
1394 * WARNINGS: *
1395 * *
1396 * HISTORY: *
1397 * 3/07/00 jga : Created. *
1398 *=============================================================================================*/
1400Radius(0.0f),
1401Slices(0),
1402Stacks(0),
1403Vertex_ct(0),
1404vtx(NULL),
1405vtx_normal(NULL),
1406vtx_uv(NULL),
1407strip_ct(0),
1408strip_size(0),
1409strips(NULL),
1410fan_ct(0),
1411fan_size(0),
1412fans(NULL),
1413face_ct(0),
1414tri_poly(NULL),
1415inverse_alpha(false)
1416{
1417
1418} // Empty SphereMesh Constructor
1419
1420
1421
1422/***********************************************************************************************
1423 * SphereMeshClass::Set_Alpha_Vector -- Unit Direction Vector, for Alpha hole effects *
1424 * *
1425 * INPUT: vector4 v ; Unit Vector pointing into the sphere in object space *
1426 * .W = Intensity ; Percent Effect *
1427 * *
1428 * OUTPUT: *
1429 * *
1430 * WARNINGS: *
1431 * *
1432 * HISTORY: *
1433 * 3/07/00 jga : Created. *
1434 *=============================================================================================*/
1435void SphereMeshClass::Set_Alpha_Vector (const AlphaVectorStruct &v, bool inverse, bool is_additive, bool force)
1436{
1437 //
1438 // Exit if there is nothing to do...
1439 //
1440 if ( alpha_vector == v &&
1441 inverse == inverse_alpha &&
1442 is_additive == IsAdditive &&
1443 !force)
1444 {
1445 return ;
1446 }
1447
1448 inverse_alpha = inverse;
1449 alpha_vector = v;
1450
1451 float Intensity = v.intensity;
1452 assert(Intensity >= 0.0f);
1453
1454 Vector3 vec = alpha_vector.angle.Rotate_Vector (Vector3 (1, 0, 0));
1455
1456 if (inverse_alpha) {
1457 for (int idx=0; idx < Vertex_ct; idx++) {
1458
1459 float temp;
1460 temp = Vector3::Dot_Product(vec, vtx_normal[idx]);
1461 temp*= Intensity;
1462
1463 temp = fabs(temp);
1464
1465 if (temp > 1.0f) temp = 1.0f;
1466
1467 Set_DCG (is_additive, idx, temp);
1468 }
1469
1470 } else {
1471
1472 for (int idx=0; idx < Vertex_ct; idx++) {
1473
1474 float temp;
1475 temp = Vector3::Dot_Product(vec, vtx_normal[idx]);
1476 temp*= Intensity;
1477
1478 temp = fabs(temp);
1479
1480 if (temp > 1.0f) temp = 1.0f;
1481
1482 Set_DCG (is_additive, idx, 1.0F - temp);
1483 }
1484 }
1485
1486 return ;
1487} // Set_Alpha_Vector
1488
1489
1490/***********************************************************************************************
1491 * SphereMeshClass::Generate -- Alloc Memory, and Generate Geometry, for the SphereMesh *
1492 * *
1493 * INPUT: *
1494 * *
1495 * OUTPUT: *
1496 * *
1497 * WARNINGS: *
1498 * *
1499 * HISTORY: *
1500 * 3/07/00 jga : Created. *
1501 *=============================================================================================*/
1502void SphereMeshClass::Generate(float radius, int slices, int stacks)
1503{
1504 // compute # of vertices
1505 // 1st 2 vertices, represent, north, and south pole (Y - axis)
1506
1507 Free();
1508
1509 Slices = slices;
1510 Stacks = stacks;
1511 Radius = radius;
1512
1513 face_ct = (Slices * Stacks * 2);
1514
1515 Vertex_ct = ((Slices+1) * Stacks) + 2;
1516
1517 vtx = W3DNEWARRAY Vector3[Vertex_ct];
1518 vtx_normal = W3DNEWARRAY Vector3[Vertex_ct];
1519 vtx_uv = W3DNEWARRAY Vector2[Vertex_ct];
1520 dcg = W3DNEWARRAY Vector4[Vertex_ct];
1521
1522 Matrix3x3 mat;
1523 Vector3 vec(0.0f, 0.0f, radius);
1524
1525 Vector3 *veclist = vtx;
1526 Vector2 *uv = vtx_uv;
1527
1528 *veclist = vec; // assign north pole
1529 veclist++;
1530
1531 // Generate Vertex UV coordinates
1532 //
1533 // 0,0 _____ 1,0
1534 // Texture maps UV's look something like this |_____|
1535 // 0,1 1,1
1536 //
1537 //
1538
1539 uv->U = 0.5f; uv->V = 0.0f; // assign uv for north pole
1540 uv++;
1541
1542 for (stacks = 0; stacks < Stacks; stacks++) {
1543
1544 float stackstep = ((float)stacks + 1) / ((float) Stacks+1);
1545 float XAxisAngle = WWMATH_PI * stackstep;
1546
1547 for (slices = 0; slices <= Slices; slices++) {
1548
1549 float slicestep = ((float)slices) / ((float)Slices);
1550 float YAxisAngle = (WWMATH_PI * 2.0f) * slicestep;
1551
1552
1553 mat.Make_Identity();
1554 mat.Rotate_Z( YAxisAngle );
1555 mat.Rotate_X( XAxisAngle );
1556 *veclist = mat * vec;
1557
1558 veclist++;
1559
1560 // update UV
1561
1562 uv->U = slicestep;
1563 uv->V = stackstep;
1564 uv++;
1565
1566 } // for slices
1567 } // for stacks
1568
1569 // Assign vertex for south pole;
1570 *veclist = -1.0f * vec;
1571 uv->U = 0.5f; uv->V = 1.0f; // uv for south pole
1572
1573 // Generate Vertex Normals
1574
1575 Vector3 *src = vtx;
1576 Vector3 *dst = vtx_normal;
1577
1578 for(int idx = 0; idx < Vertex_ct; idx++) {
1579
1580 Vector3 temp;
1581
1582 temp = src[idx];
1583 temp.Normalize();
1584 dst[idx] = temp;
1585 }
1586
1587
1588 // Generate Fans for North + south pole
1589 fan_ct = 2;
1590 fan_size = Slices+2;
1591 fans = W3DNEWARRAY int[fan_size * fan_ct];
1592
1593 // Do Fan #1
1594 for (int ct = 0; ct < fan_size; ct++) {
1595 fans[ct] = ct;
1596 }
1597 //fans[ct] = 1;
1598
1599 // Do Fan #2
1600 int vtx_idx = Vertex_ct - 1;
1601 for (ct = fan_size; ct < (fan_size * 2); ct++) {
1602 fans[ct] = vtx_idx;
1603 vtx_idx--;
1604 }
1605 //fans[ct] = Vertex_ct - 2;
1606
1607 // Generate Strips, for the inbetween stacks
1608
1609 strip_size = ((Slices+1) * 2);
1610 strip_ct = Stacks - 1;
1611 if (strip_ct) {
1612 strips = W3DNEWARRAY int[strip_size * strip_ct];
1613 for (stacks = 0; stacks < strip_ct; stacks++) {
1614 // outer loop for each stack
1615 int store_idx = stacks * strip_size;
1616 int base_vtx = 1 + (stacks * (Slices+1));
1617 int cur_vtx = base_vtx;
1618
1619 for(ct = 0; ct <= Slices; ct++) {
1620
1621 strips[store_idx] = cur_vtx + (Slices+1);
1622 strips[store_idx+1] = cur_vtx;
1623
1624 cur_vtx++;
1625 store_idx+=2;
1626
1627 }
1628
1629 // Last, special case +2
1630 //strips[store_idx] = base_vtx + Slices;
1631 //strips[store_idx+1] = base_vtx;
1632 }
1633 }
1634
1635 // Generate Tri-Poly Indices
1636
1637 tri_poly = W3DNEWARRAY TriIndex[face_ct]; // 3 indices per triangle
1638
1639 TriIndex *out = tri_poly;
1640 int *in;
1641
1642 for (stacks = 0; stacks < strip_ct; stacks++) {
1643
1644 in = &strips[strip_size * stacks];
1645
1646 // Strip to Poly Function
1647 // IJK
1648 for(int fidx=0; fidx < (strip_size - 2); fidx++) {
1649
1650 out->I = in[0];
1651 out->J = in[1];
1652 out->K = in[2];
1653
1654 out++;
1655 in++;
1656
1657 fidx++;
1658 if (fidx >= (strip_size-2)) break;
1659
1660 out->I = in[0];
1661 out->J = in[2];
1662 out->K = in[1];
1663 out++;
1664 in++;
1665
1666 }
1667
1668 // End Strip to Poly Function
1669 }
1670
1671
1672 // Fans to Poly Function
1673
1674 for(slices = 0; slices < fan_ct; slices++) {
1675
1676 in = &fans[fan_size * slices];
1677 int *base_idx = in;
1678
1679 for (int fidx=0; fidx < (fan_size - 2); fidx++) {
1680
1681 out->I = base_idx[0];
1682 out->J = in[2];
1683 out->K = in[1];
1684
1685 in++;
1686 out++;
1687 }
1688
1689 }
1690
1691 // Make Sure ptr is where I expect it to be
1692 WWASSERT(((int)out) == ((int)(tri_poly + face_ct)));
1693
1694 //
1695 // Fill in the DCG array
1696 //
1697 Set_Alpha_Vector (alpha_vector, inverse_alpha, IsAdditive, true);
1698 return ;
1699
1700} // Generate
1701
1702
1703
1704/***********************************************************************************************
1705 * SphereMeshClass::~SphereMeshClass -- Destructor *
1706 * *
1707 * WARNINGS: *
1708 * *
1709 * HISTORY: *
1710 * 3/07/00 jga : Created. *
1711 *=============================================================================================*/
1713{
1714
1715 Free();
1716
1717} // Destructor
1718
1719
1720/***********************************************************************************************
1721 * SphereMeshClass::Free Memory used by geometry for the SphereMesh *
1722 * *
1723 * INPUT: *
1724 * *
1725 * OUTPUT: *
1726 * *
1727 * WARNINGS: *
1728 * *
1729 * HISTORY: *
1730 * 3/07/00 jga : Created. *
1731 *=============================================================================================*/
1732void SphereMeshClass::Free(void)
1733{
1734 if (vtx) delete [] vtx;
1735 if (vtx_normal) delete [] vtx_normal;
1736 if (vtx_uv) delete [] vtx_uv;
1737 if (dcg) delete [] dcg;
1738 if (strips) delete [] strips;
1739 if (fans) delete [] fans;
1740 if (tri_poly) delete [] tri_poly;
1741
1742 vtx = NULL;
1743 vtx_normal = NULL;
1744 vtx_uv = NULL;
1745 dcg = NULL;
1746 strips = NULL;
1747 fans = NULL;
1748 tri_poly = NULL;
1749
1750}
1751
1752// EOF - sphereobj.cpp
1753
#define NULL
Definition BaseType.h:92
void const char * value
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
#define WWASSERT
#define SORT_LEVEL_NONE
Definition w3d_file.h:1195
#define W3D_NAME_LEN
Definition w3d_file.h:319
@ W3D_CHUNK_SPHERE
Definition w3d_file.h:474
#define W3DNEWARRAY
Definition always.h:110
#define W3DNEW
Definition always.h:109
@ true
Definition bool.h:59
@ false
Definition bool.h:59
#define WWMATH_PI
Definition wwmath.h:56
T Bound(T original, T minval, T maxval)
Definition bound.h:44
WWINLINE void Init(const Vector3 &center, const Vector3 &extent)
Definition aabox.h:101
Vector3 Center
Definition aabox.h:123
Vector3 Extent
Definition aabox.h:124
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
uint32 Read(void *buf, uint32 nbytes)
Definition chunkio.cpp:692
bool Open_Chunk()
Definition chunkio.cpp:412
uint32 Write(const void *buf, uint32 nbytes)
Definition chunkio.cpp:264
bool Begin_Chunk(uint32 id)
Definition chunkio.cpp:108
bool End_Chunk()
Definition chunkio.cpp:148
static void Set_Vertex_Buffer(const VertexBufferClass *vb, unsigned stream=0)
static void Set_Texture(unsigned stage, TextureBaseClass *texture)
static void Set_Index_Buffer(const IndexBufferClass *ib, unsigned short index_base_offset)
static Vector4 Convert_Color(unsigned color)
Definition dx8wrapper.h:958
static void Draw_Triangles(unsigned buffer_type, unsigned short start_index, unsigned short polygon_count, unsigned short min_vertex_index, unsigned short vertex_count)
static void Set_Material(const VertexMaterialClass *material)
static void Set_Shader(const ShaderClass &shader)
static void Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4 &m)
static void Set_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
VertexFormatXYZNDUV2 * Get_Formatted_Vertex_Array()
void Translate(float x, float y, float z)
Definition matrix3d.h:670
WWINLINE void Scale(float scale)
Definition matrix3d.h:975
WWINLINE void Rotate_X(float theta)
Definition matrix3.h:782
WWINLINE void Make_Identity(void)
Definition matrix3.h:326
WWINLINE void Rotate_Z(float theta)
Definition matrix3.h:851
static WWINLINE void Transform_Vector(const Matrix4x4 &tm, const Vector3 &in, Vector3 *out)
Definition matrix4.h:801
static void Add_Object(RenderObjClass *robj)
Definition predlod.cpp:226
virtual float Get_Screen_Size(CameraClass &camera)
Definition rendobj.cpp:324
Vector3 Get_Position(void) const
Definition rendobj.cpp:508
virtual void Set_Transform(const Matrix3D &m)
Definition rendobj.cpp:423
void Validate_Cached_Bounding_Volumes(void) const
Definition rendobj.h:524
virtual int Is_Not_Hidden_At_All(void)
Definition rendobj.h:463
RenderObjClass(void)
Definition rendobj.cpp:170
virtual void Set_Position(const Vector3 &v)
Definition rendobj.cpp:444
virtual const SphereClass & Get_Bounding_Sphere(void) const
Definition rendobj.h:567
AABoxClass CachedBoundingBox
Definition rendobj.h:553
RenderObjClass & operator=(const RenderObjClass &)
Definition rendobj.cpp:232
static const float AT_MAX_LOD
Definition rendobj.h:405
Matrix3D Transform
Definition rendobj.h:549
SphereClass CachedBoundingSphere
Definition rendobj.h:552
static const float AT_MIN_LOD
Definition rendobj.h:404
@ TEXTURING_DISABLE
Definition shader.h:219
@ TEXTURING_ENABLE
Definition shader.h:220
@ CULL_MODE_DISABLE
Definition shader.h:158
static ShaderClass _PresetAlphaShader
Definition shader.h:374
void Enable_Fog(const char *source)
Definition shader.cpp:280
@ ALPHATEST_DISABLE
Definition shader.h:96
@ DSTBLEND_ZERO
Definition shader.h:172
@ DSTBLEND_ONE
Definition shader.h:173
static void Insert_Triangles(const SphereClass &bounding_sphere, unsigned short start_index, unsigned short polygon_count, unsigned short min_vertex_index, unsigned short vertex_count)
VisRasterizerClass * VisRasterizer
Definition rinfo.h:153
void Init(const Vector3 &pos, float radius)
Definition sphere.h:248
virtual PrototypeClass * Load_W3D(ChunkLoadClass &cload)
void Generate(float radius, int slices, int stacks)
void Set_Alpha_Vector(const AlphaVectorStruct &v, bool inverse, bool is_additive, bool force=false)
virtual RenderObjClass * Create(void)
virtual int Get_Class_ID(void) const
bool Load(ChunkLoadClass &cload)
bool Save(ChunkSaveClass &csave)
virtual const char * Get_Name(void) const
SphereRenderObjClass & operator=(const SphereRenderObjClass &)
AABoxClass CachedBox
Definition sphereobj.h:395
void Set_Animation_Duration(float time)
Definition sphereobj.h:324
virtual void Scale(float scale)
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
TextureClass * SphereTexture
Definition sphereobj.h:393
virtual int Get_Num_Polys(void) const
virtual int Get_LOD_Level(void) const
virtual int Class_ID(void) const
AlphaVectorStruct Get_Default_Vector(void) const
Vector3 Get_Default_Color(void) const
virtual float Get_Post_Increment_Value(void) const
const SphereVectorChannelClass & Peek_Vector_Channel(void)
Definition sphereobj.h:338
AlphaVectorStruct CurrentVector
Definition sphereobj.h:384
float Value[SPHERE_NUM_LOD+2]
Definition sphereobj.h:365
unsigned int Flags
Definition sphereobj.h:389
void Set_Alpha_Channel(const SphereAlphaChannelClass &data)
Definition sphereobj.h:341
void Set_Scale_Channel(const SphereScaleChannelClass &data)
Definition sphereobj.h:342
float Get_Default_Alpha(void) const
virtual void Set_LOD_Level(int lod)
SphereAlphaChannelClass AlphaChannel
Definition sphereobj.h:368
SphereScaleChannelClass ScaleChannel
Definition sphereobj.h:369
void Start_Animating(void)
Definition sphereobj.h:292
virtual const char * Get_Name(void) const
SphereColorChannelClass ColorChannel
Definition sphereobj.h:367
void Set_Vector_Channel(const SphereVectorChannelClass &data)
Definition sphereobj.h:343
static void Generate_Shared_Mesh_Arrays(const AlphaVectorStruct &alphavector)
void Set_Flags(unsigned int flags)
Definition sphereobj.h:287
virtual void Special_Render(SpecialRenderInfoClass &rinfo)
virtual void Render(RenderInfoClass &rinfo)
virtual void Update_Cached_Bounding_Volumes(void) const
virtual void Decrement_LOD(void)
bool Is_Animating(void)
Definition sphereobj.h:291
virtual int Get_LOD_Count(void) const
const SphereColorChannelClass & Peek_Color_Channel(void)
Definition sphereobj.h:329
ShaderClass SphereShader
Definition sphereobj.h:392
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &aabox) const
void Update_On_Visibilty(void)
virtual void Set_Position(const Vector3 &v)
virtual void update_cached_box(void)
SphereVectorChannelClass VectorChannel
Definition sphereobj.h:370
void Set_Local_Center_Extent(const Vector3 &center, const Vector3 &extent)
Definition sphereobj.h:408
virtual void Set_Transform(const Matrix3D &m)
char Name[2 *W3D_NAME_LEN]
Definition sphereobj.h:376
Quaternion Orientation
Definition sphereobj.h:386
const SphereScaleChannelClass & Peek_Scale_Channel(void)
Definition sphereobj.h:335
void calculate_value_array(float screen_area, float *values) const
const SphereAlphaChannelClass & Peek_Alpha_Channel(void)
Definition sphereobj.h:332
VertexMaterialClass * SphereMaterial
Definition sphereobj.h:391
void Set_Texture(TextureClass *tf)
virtual int Calculate_Cost_Value_Arrays(float screen_area, float *values, float *costs) const
virtual float Get_Cost(void) const
void vis_render_sphere(SpecialRenderInfoClass &rinfo, const Vector3 &center, const Vector3 &extent)
unsigned int Get_Flags(void)
Definition sphereobj.h:286
virtual float Get_Value(void) const
void Init_Material(void)
void Set_Color_Channel(const SphereColorChannelClass &data)
Definition sphereobj.h:340
virtual void Increment_LOD(void)
const AABoxClass & Get_Box(void)
Definition sphereobj.h:423
void Stop_Animating(void)
Definition sphereobj.h:293
virtual void Prepare_LOD(CameraClass &camera)
virtual RenderObjClass * Clone(void) const
Vector3 Get_Default_Scale(void) const
virtual void Set_Name(const char *name)
const StringClass & Get_Full_Path(void) const
Definition texture.h:113
float V
Definition vector2.h:80
float Y
Definition vector2.h:79
float X
Definition vector2.h:74
float U
Definition vector2.h:75
static WWINLINE float Dot_Product(const Vector3 &a, const Vector3 &b)
Definition vector3.h:293
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
void Normalize(void)
Definition vector3.h:417
unsigned short K
Definition Vector3i.h:102
unsigned short J
Definition Vector3i.h:101
unsigned short I
Definition Vector3i.h:100
float Y
Definition vector4.h:67
float Z
Definition vector4.h:68
float X
Definition vector4.h:66
void Set_Model_Transform(const Matrix3D &model)
static void Convert_Vector(const W3dVectorStruct &v, Vector3 *set)
Definition w3d_util.cpp:45
static void Convert_Shader(const W3dShaderStruct &shader, ShaderClass *set)
Definition w3d_util.cpp:106
virtual TextureClass * Get_Texture(const char *filename, MipCountType mip_level_count=MIP_LEVELS_ALL, WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN, bool allow_compression=true, TextureBaseClass::TexAssetType type=TextureBaseClass::TEX_REGULAR, bool allow_reduction=true)
static WW3DAssetManager * Get_Instance(void)
Definition assetmgr.h:205
static unsigned int Get_Frame_Time(void)
Definition ww3d.h:173
static void Add_To_Static_Sort_List(RenderObjClass *robj, unsigned int sort_level)
Definition ww3d.cpp:1984
static bool Are_Static_Sort_Lists_Enabled(void)
Definition ww3d.h:282
static bool Is_Sorting_Enabled(void)
Definition ww3d.h:220
const unsigned dynamic_fvf_type
@ BUFFER_TYPE_DYNAMIC_DX8
Definition dx8wrapper.h:90
@ BUFFER_TYPE_DYNAMIC_SORTING
Definition dx8wrapper.h:91
Vector3i16 TriIndex
else return(RetVal)
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define REF_PTR_SET(dst, src)
Definition refcount.h:79
#define NEW_REF(C, P)
Definition refcount.h:62
@ CHUNKID_ALPHA_CHANNEL
Definition ringobj.cpp:1276
@ CHUNKID_COLOR_CHANNEL
Definition ringobj.cpp:1275
SphereLoaderClass _SphereLoader
SphereMeshClass SphereMeshArray[SPHERE_NUM_LOD]
Definition sphereobj.cpp:96
@ CHUNKID_SCALE_CHANNEL
@ CHUNKID_VECTOR_CHANNEL
@ CHUNKID_SPHERE_DEF
float SphereLODCosts[SPHERE_NUM_LOD+1]
Definition sphereobj.cpp:97
#define SPHERE_NUM_LOD
Definition sphereobj.h:221
#define SPHERE_HIGHEST_LOD
Definition sphereobj.h:223
#define SPHERE_LOWEST_LOD
Definition sphereobj.h:222
char Name[2 *W3D_NAME_LEN]
Definition sphereobj.h:123
W3dVectorStruct Extent
Definition sphereobj.h:126
W3dVectorStruct Center
Definition sphereobj.h:125
char TextureName[2 *W3D_NAME_LEN]
Definition sphereobj.h:135