convert line ends
[canaan.git] / prj / cam / src / render / slitprop.cpp
blob9efb3dba41df1a186400cf758430c912bd3e858a
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/render/slitprop.cpp,v 1.15 1999/03/04 17:30:37 XEMU Exp $
8 #include <propert_.h>
9 #include <propface.h>
10 #include <objslit.h>
11 #include <slitprop.h>
12 #include <objlight.h>
13 #include <objpos.h>
14 #include <rendprop.h>
15 #include <stdlib.h>
16 #include <math.h>
17 #include <osysbase.h>
18 #include <portal.h>
19 #include <litprop.h>
22 // Must be last header
23 #include <dbmem.h>
26 ////////////////////////////////////////////////////////////
27 // SELF-ILLUMINATION PROP API
31 ////////////////////////////////////////////////////////////
32 // SELF-ILLUMINATION PROPERTY CREATION
35 static IIntProperty* gSelfLitProp = NULL;
37 static sPropertyDesc selflitprop_desc =
39 PROP_SELF_LIT_NAME,
40 kPropertyNoInherit|kPropertyInstantiate,
41 NULL, 0, 0,
42 { "Renderer", "Dynamic Light" },
45 void SelfLitPropInit(void)
47 gSelfLitProp = CreateIntProperty(&selflitprop_desc, kPropertyImplDense);
51 BOOL ObjGetSelfLit(ObjID obj, int *psl)
53 if (gSelfLitProp)
55 BOOL retval = gSelfLitProp->Get(obj,psl);
56 return retval;
58 return FALSE;
61 BOOL ObjSetSelfLit(ObjID obj, int sl)
64 if (gSelfLitProp)
66 gSelfLitProp->Set(obj,sl);
67 return TRUE;
69 return FALSE;
74 // Update all self-lit objects
77 extern "C" BOOL g_lgd3d;
79 void SelfLitUpdateAll(void)
81 if (!gSelfLitProp)
82 return;
84 IIntProperty* prop = gSelfLitProp;
85 sPropertyObjIter iter;
86 ObjID obj;
87 int light;
89 prop->IterStart(&iter);
90 while(prop->IterNextValue(&iter,&obj,&light))
91 if (OBJ_IS_CONCRETE(obj) && ObjHasRefs(obj))
93 ObjPos* pos = ObjPosGet(obj);
94 // @HACK for EEE: larger radius in hardware
95 #ifdef RGB_LIGHTING
97 float hue,saturation;
98 int r,g,b;
99 ObjColorGet(obj, &hue, &saturation);
100 portal_convert_hsb_to_rgb(&r,&g,&b,hue,saturation);
101 portal_set_normalized_color(r,g,b);
103 #endif
104 add_dynamic_light(&pos->loc, light, g_lgd3d ? 10.0 : 4.0);
106 prop->IterStop(&iter);
110 static IIntProperty* g_pShadowProp = NULL;
112 static sPropertyDesc shadow_prop_desc =
114 PROP_SHADOW_NAME,
115 kPropertyNoInherit|kPropertyInstantiate,
116 NULL, 0, 0,
117 { "Renderer", "Shadow" },
120 void ShadowPropInit(void)
122 g_pShadowProp = CreateIntProperty(&shadow_prop_desc,
123 kPropertyImplLlist);
127 BOOL ObjGetShadow(ObjID obj, int *s)
129 if (g_pShadowProp) {
130 BOOL retval = g_pShadowProp->Get(obj, s);
131 return retval;
133 return FALSE;
136 BOOL ObjSetShadow(ObjID obj, int s)
138 if (g_pShadowProp)
140 g_pShadowProp->Set(obj, s);
141 return TRUE;
143 return FALSE;
148 // Update all objects with shadows
151 // Up to this distance from the object's center, the shadow is
152 // at full strength.
153 #define kShadowCutoff 6.0
154 // If the floor is further than this, there's no shadow.
155 #define kShadowMaxDist 15.0
157 void ShadowUpdateAll(void)
159 if (!g_pShadowProp)
160 return;
162 IIntProperty* prop = g_pShadowProp;
163 sPropertyObjIter iter;
164 ObjID obj;
165 int iLevel;
166 float fIntensity;
167 float fZDiff;
168 ObjPos *pos;
169 Location EndLoc, HitLoc;
171 prop->IterStart(&iter);
172 while(prop->IterNextValue(&iter, &obj, &iLevel))
173 if (OBJ_IS_CONCRETE(obj) && ObjHasRefs(obj)) {
174 fIntensity = iLevel;
175 pos = ObjPosGet(obj);
176 EndLoc = pos->loc;
177 HitLoc = EndLoc;
178 EndLoc.vec.z -= kShadowMaxDist;
180 if (!PortalRaycast(&pos->loc, &EndLoc, &HitLoc, 0)) {
181 fZDiff = pos->loc.vec.z - HitLoc.vec.z;
182 if (fZDiff > kShadowCutoff)
183 fIntensity *= (kShadowMaxDist - fZDiff)
184 / (kShadowMaxDist - kShadowCutoff);
186 HitLoc.vec.z += .1;
187 portal_add_simple_dynamic_dark(fIntensity, fIntensity,
188 &HitLoc, 8.0);
191 prop->IterStop(&iter);