12#ifndef TT_INCLUDE__RENDEROBJCLASS_H
13#define TT_INCLUDE__RENDEROBJCLASS_H
17#include "AABoxClass.h"
18#include "SphereClass.h"
19#include "engine_vector.h"
21#include "engine_string.h"
24class AABoxCollisionTestClass;
25class AABoxIntersectionTestClass;
27class DecalGeneratorClass;
31class IntersectionClass;
32class IntersectionResultClass;
33class OBBoxCollisionTestClass;
34class OBBoxIntersectionTestClass;
35class RayCollisionTestClass;
38class SpecialRenderInfoClass;
40class MaterialInfoClass;
43class RenderObjClass :
public RefCountClass,
public PersistClass,
public MultiListObjectClass
48 mutable unsigned long Bits;
50 mutable SphereClass CachedBoundingSphere;
51 mutable AABoxClass CachedBoundingBox;
52 float NativeScreenSize;
53 mutable bool IsTransformIdentity;
55 RenderObjClass* Container;
67 COLLISION_TYPE_MASK = 0xff,
69 IS_NOT_HIDDEN = 0x200,
70 IS_NOT_ANIMATION_HIDDEN = 0x400,
71 IS_FORCE_VISIBLE = 0x800,
72 BOUNDING_VOLUMES_VALID = 0x2000,
73 IS_TRANSLUCENT = 0x4000,
74 SUBOBJS_MATCH_LOD = 0x10000,
75 SUBOBJ_TRANSFORMS_DIRTY = 0x20000,
76 HAS_USER_LIGHTING = 0x40000,
77 IS_REALLY_VISIBLE = 0x700,
78 IS_NOT_HIDDEN_AT_ALL = 0x600,
84 CLASSID_UNKNOWN = 0xFFFFFFFF,
95 CLASSID_DYNASCREENMESH,
100 CLASSID_PARTICLEEMITTER,
101 CLASSID_PARTICLEBUFFER,
102 CLASSID_SCREENPOINTGROUP,
103 CLASSID_VIEWPOINTGROUP,
104 CLASSID_WORLDPOINTGROUP,
119 CLASSID_SEGLINETRAIL,
121 CLASSID_RENEGADE_TERRAIN,
123 CLASSID_USERCLIPPLANECAMERA,
124 CLASSID_PLANEREFLECTIONCAMERA,
127 CLASSID_LAST = 0x0000FFFF
131 RenderObjClass(
const RenderObjClass& src);
132 RenderObjClass& operator=(
const RenderObjClass& that);
133 virtual ~RenderObjClass() {}
135 virtual RenderObjClass* Clone ()
const = 0;
136 virtual int Class_ID ()
const {
return CLASSID_UNKNOWN; }
137 virtual const char* Get_Name ()
const {
return "UNNAMED"; }
138 virtual void Set_Name (
const char*) { }
139 virtual const char* Get_Base_Model_Name ()
const {
return NULL; }
140 virtual void Set_Base_Model_Name (
const char*) { }
141 virtual int Get_Num_Polys ()
const {
return 0; }
142 virtual void Render (RenderInfoClass&) = 0;
143 virtual void Special_Render (SpecialRenderInfoClass&) { }
144 virtual void On_Frame_Update () { }
145 virtual void Restart () { }
146 virtual void Add (SceneClass*);
147 virtual void Remove ();
148 virtual SceneClass* Get_Scene ();
149 virtual SceneClass* Peek_Scene () {
return Scene; }
150 virtual void Set_Container (RenderObjClass*);
151 virtual RenderObjClass* Get_Container ()
const;
152 virtual void Validate_Transform ()
const;
153 virtual void Set_Transform (
const Matrix3D&);
154 virtual void Set_Position (
const Vector3&);
155 const Matrix3D & Get_Transform(
void)
const;
156 const Matrix3D & Get_Transform(
bool& is_transform_identity)
const;
157 const Matrix3D & Get_Transform_No_Validity_Check(
void)
const;
158 const Matrix3D & Get_Transform_No_Validity_Check(
bool& is_transform_identity)
const;
159 bool Is_Transform_Identity()
const;
160 bool Is_Transform_Identity_No_Validity_Check()
const;
161 Vector3 Get_Position(
void)
const;
162 virtual void Notify_Added (SceneClass*);
163 virtual void Notify_Removed (SceneClass*);
164 virtual int Get_Num_Sub_Objects ()
const {
return 0; }
165 virtual RenderObjClass* Get_Sub_Object (
int index)
const {
return NULL; }
166 virtual int Add_Sub_Object (RenderObjClass*) {
return 0; }
167 virtual int Remove_Sub_Object (RenderObjClass*) {
return 0; }
168 virtual RenderObjClass* Get_Sub_Object_By_Name (
const char* name)
const;
169 virtual int Get_Num_Sub_Objects_On_Bone (
int boneIndex)
const {
return 0; }
170 virtual RenderObjClass* Get_Sub_Object_On_Bone (
int index,
int boneIndex)
const {
return NULL; }
171 virtual int Get_Sub_Object_Bone_Index (RenderObjClass*
object)
const {
return 0; }
172 virtual int Add_Sub_Object_To_Bone (RenderObjClass*,
int boneIndex) {
return 0; }
173 virtual int Add_Sub_Object_To_Bone (RenderObjClass*,
const char*);
174 virtual int Remove_Sub_Objects_From_Bone (
const char* boneName);
175 virtual void Update_Sub_Object_Transforms ();
176 virtual void Set_Animation () { }
177 virtual void Set_Animation (HAnimClass*,
float,
int anim_mode = ANIM_MODE_MANUAL) { }
178 virtual void Set_Animation (HAnimClass*,
float, HAnimClass*,
float,
float) { }
179 virtual void Set_Animation (HAnimComboClass*) { }
180 virtual HAnimClass* Peek_Animation () {
return NULL; }
181 virtual int Get_Num_Bones () {
return 0; }
182 virtual const char* Get_Bone_Name (
int boneIndex) {
return NULL; }
183 virtual int Get_Bone_Index (
const char* boneName) {
return 0; }
184 virtual const Matrix3D& Get_Bone_Transform (
const char* boneName) {
return Get_Transform(); }
185 virtual const Matrix3D& Get_Bone_Transform (
int boneIndex) {
return Get_Transform(); }
186 virtual void Capture_Bone (
int boneIndex) { }
187 virtual void Release_Bone (
int boneIndex) { }
188 virtual bool Is_Bone_Captured (
int boneIndex)
const {
return false; }
189 virtual void Control_Bone (
int boneIndex,
const Matrix3D&,
bool b =
false) { }
190 virtual const HTreeClass * Get_HTree(
void)
const {
return NULL; }
191 virtual bool Cast_Ray (RayCollisionTestClass&) {
return false; }
192 virtual bool Cast_AABox (AABoxCollisionTestClass&) {
return false; }
193 virtual bool Cast_OBBox (OBBoxCollisionTestClass&) {
return false; }
194 virtual bool Intersect_AABox (AABoxIntersectionTestClass&) {
return false; }
195 virtual bool Intersect_OBBox (OBBoxIntersectionTestClass&) {
return false; }
196 virtual bool Intersect (IntersectionClass*, IntersectionResultClass*);
197 virtual bool Intersect_Sphere (IntersectionClass*, IntersectionResultClass*);
198 virtual bool Intersect_Sphere_Quick (IntersectionClass*, IntersectionResultClass*);
199 virtual const SphereClass& Get_Bounding_Sphere ()
const;
200 virtual const AABoxClass& Get_Bounding_Box ()
const;
201 virtual void Get_Obj_Space_Bounding_Sphere (SphereClass&)
const;
202 virtual void Get_Obj_Space_Bounding_Box (AABoxClass&)
const;
203 virtual void Update_Obj_Space_Bounding_Volumes () { }
204 static const float AT_MIN_LOD;
205 static const float AT_MAX_LOD;
206 virtual void Prepare_LOD (CameraClass&);
207 virtual void Recalculate_Static_LOD_Factors () { }
208 virtual void Increment_LOD () { }
209 virtual void Decrement_LOD () { }
210 virtual float Get_Cost ()
const;
211 virtual float Get_Value ()
const {
return AT_MIN_LOD; }
212 virtual float Get_Post_Increment_Value ()
const {
return AT_MAX_LOD; }
213 virtual void Set_LOD_Level (
int) { }
214 virtual int Get_LOD_Level ()
const {
return 0; }
215 virtual int Get_LOD_Count ()
const {
return 1; }
216 virtual void Set_LOD_Bias (
float) { }
217 virtual int Calculate_Cost_Value_Arrays (
float,
float*,
float*)
const;
218 virtual RenderObjClass * Get_Current_LOD () { Add_Ref();
return this; }
219 virtual bool Build_Dependency_List (DynamicVectorClass<StringClass> &file_list,
bool recursive=
true);
220 virtual bool Build_Texture_List (DynamicVectorClass<StringClass> &texture_file_list,
bool recursive=
true);
221 virtual void Create_Decal (DecalGeneratorClass*) { }
222 virtual void Delete_Decal (uint32) { }
223 virtual MaterialInfoClass* Get_Material_Info () {
return NULL; }
224 virtual void Set_User_Data (
void* value,
bool) { User_Data = value; };
225 virtual void* Get_User_Data () {
return User_Data; };
226 virtual int Get_Num_Snap_Points () {
return 0; }
227 virtual void Get_Snap_Point (
int, Vector3*) { }
228 virtual float Get_Screen_Size (CameraClass&);
229 virtual void Scale (
float) { };
230 virtual void Scale (
float,
float,
float) { };
231 virtual int Get_Sort_Level ()
const {
return 0;}
232 virtual void Set_Sort_Level (
int) { }
233 virtual int Is_Really_Visible () {
return ((Bits & IS_REALLY_VISIBLE) == IS_REALLY_VISIBLE); }
234 virtual int Is_Not_Hidden_At_All () {
return ((Bits & IS_NOT_HIDDEN_AT_ALL) == IS_NOT_HIDDEN_AT_ALL); }
235 virtual int Is_Visible ()
const {
return (Bits & IS_VISIBLE); }
236 virtual void Set_Visible (
int onoff) {
if (onoff) { Bits |= IS_VISIBLE; }
else { Bits &= ~IS_VISIBLE; } }
237 virtual int Is_Hidden ()
const {
return !(Bits & IS_NOT_HIDDEN); }
238 virtual void Set_Hidden (
int onoff) {
if (onoff) { Bits &= ~IS_NOT_HIDDEN; }
else { Bits |= IS_NOT_HIDDEN; } }
239 virtual int Is_Animation_Hidden ()
const {
return !(Bits & IS_NOT_ANIMATION_HIDDEN); }
240 virtual void Set_Animation_Hidden (
int onoff) {
if (onoff) { Bits &= ~IS_NOT_ANIMATION_HIDDEN; }
else { Bits |= IS_NOT_ANIMATION_HIDDEN; } }
241 virtual int Is_Force_Visible ()
const {
return Bits & IS_FORCE_VISIBLE; }
242 virtual void Set_Force_Visible (
int onoff) {
if (onoff) { Bits |= IS_FORCE_VISIBLE; }
else { Bits &= ~IS_FORCE_VISIBLE; } }
243 virtual int Has_User_Lighting ()
const {
return Bits & HAS_USER_LIGHTING; }
244 virtual void Set_Has_User_Lighting (
bool onoff) {
if (onoff) { Bits |= HAS_USER_LIGHTING; }
else { Bits &= ~HAS_USER_LIGHTING; } }
245 virtual int Is_Translucent ()
const {
return Bits & IS_TRANSLUCENT; }
246 virtual void Set_Translucent (
int onoff) {
if (onoff) { Bits |= IS_TRANSLUCENT; }
else { Bits &= ~IS_TRANSLUCENT; } }
247 virtual int Get_Collision_Type ()
const {
return (Bits & COLLISION_TYPE_MASK); }
248 virtual void Set_Collision_Type (
int type) { Bits &= ~COLLISION_TYPE_MASK; Bits |= (type & COLLISION_TYPE_MASK) | 1; }
249 virtual bool Is_Complete () {
return false; }
250 virtual bool Is_In_Scene () {
return Scene != NULL; }
251 virtual float Get_Native_Screen_Size ()
const {
return NativeScreenSize; }
252 virtual void Set_Native_Screen_Size (
float screensize) { NativeScreenSize = screensize; }
253 virtual const PersistFactoryClass& Get_Factory ()
const;
254 virtual bool Save (ChunkSaveClass& oSave);
255 virtual bool Load (ChunkLoadClass& oLoad);
256 virtual void Save_User_Lighting (ChunkSaveClass&);
257 virtual void Load_User_Lighting (ChunkLoadClass&);
258 virtual void Add_Dependencies_To_List (DynamicVectorClass<StringClass> &file_list,
bool textures_only =
false);
259 virtual void Update_Cached_Bounding_Volumes ()
const;
260 virtual void Update_Sub_Object_Bits ();
261 void Set_Sub_Objects_Match_LOD(
int onoff) {
if (onoff) { Bits |= SUBOBJS_MATCH_LOD; }
else { Bits &= ~SUBOBJS_MATCH_LOD; } }
262 int Is_Sub_Objects_Match_LOD_Enabled(
void) {
return Bits & SUBOBJS_MATCH_LOD; }
263 void Set_Sub_Object_Transforms_Dirty(
bool onoff) {
if (onoff) { Bits |= SUBOBJ_TRANSFORMS_DIRTY; }
else { Bits &= ~SUBOBJ_TRANSFORMS_DIRTY; } }
264 bool Are_Sub_Object_Transforms_Dirty(
void);
265 bool Bounding_Volumes_Valid(
void)
const;
266 void Invalidate_Cached_Bounding_Volumes(
void)
const { Bits &= ~BOUNDING_VOLUMES_VALID; }
267 void Validate_Cached_Bounding_Volumes(
void)
const { Bits |= BOUNDING_VOLUMES_VALID; }
268 void Save_Sub_Object_User_Lighting(ChunkSaveClass & csave,RenderObjClass * sub_obj,
int bone_index);
269 void Load_Sub_Object_User_Lighting(ChunkLoadClass & cload);
270 void Set_User_Lighting_Flag();
272 void Register_For_Rendering(
bool hint_static =
false);
276TT_INLINE
const SphereClass & RenderObjClass::Get_Bounding_Sphere(
void)
const
278 if (!Bounding_Volumes_Valid()) {
279 Update_Cached_Bounding_Volumes();
281 return CachedBoundingSphere;
283TT_INLINE
const AABoxClass & RenderObjClass::Get_Bounding_Box(
void)
const
285 if (!Bounding_Volumes_Valid()) {
286 Update_Cached_Bounding_Volumes();
288 return CachedBoundingBox;
290TT_INLINE
float Bound_Degrees(
float angle)
292 while (angle > 359) angle -= 360;
293 while (angle < 0) angle += 360;
296TT_INLINE
const Matrix3D & RenderObjClass::Get_Transform(
void)
const
298 Validate_Transform();
301TT_INLINE
const Matrix3D & RenderObjClass::Get_Transform(
bool &is_transform_identity)
const
303 Validate_Transform();
304 is_transform_identity=IsTransformIdentity;
307TT_INLINE
bool RenderObjClass::Is_Transform_Identity()
const
309 Validate_Transform();
310 return IsTransformIdentity;
312TT_INLINE
const Matrix3D & RenderObjClass::Get_Transform_No_Validity_Check(
void)
const
316TT_INLINE
const Matrix3D & RenderObjClass::Get_Transform_No_Validity_Check(
bool& is_transform_identity)
const
318 is_transform_identity=IsTransformIdentity;
321TT_INLINE
bool RenderObjClass::Is_Transform_Identity_No_Validity_Check()
const
323 return IsTransformIdentity;
326typedef RefMultiListClass<RenderObjClass> RefRenderObjListClass;
327typedef RefMultiListIterator<RenderObjClass> RefRenderObjListIterator;
329typedef MultiListClass<RenderObjClass> NonRefRenderObjListClass;
330typedef MultiListIterator<RenderObjClass> NonRefRenderObjListIterator;