| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : wwphys *
- * *
- * $Archive:: /Commando/Code/wwphys/vehicledazzle.cpp $*
- * *
- * Original Author:: Greg Hjelstrom *
- * *
- * $Author:: Greg_h $*
- * *
- * $Modtime:: 12/02/01 1:33p $*
- * *
- * $Revision:: 5 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * VehicleDazzleClass::VehicleDazzleClass -- Constructor *
- * VehicleDazzleClass::~VehicleDazzleClass -- Destructor *
- * VehicleDazzleClass::Set_Model -- sets the dazzle model for this object to control *
- * VehicleDazzleClass::Set_Time_Of_Day -- updates any parameters which depend on time of day *
- * VehicleDazzleClass::Pre_Render_Update -- Update dazzle state prior to rendering *
- * VehicleDazzleClass::Is_Vehicle_Dazzle -- static function for filtering vehicle dazzles *
- * VehicleDazzleClass::Determine_Type -- Determine the type of vehicle dazzle this is *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "vehicledazzle.h"
- #include "dazzle.h"
- #include "ww3d.h"
- #include "vehiclephys.h"
- #include "physcontrol.h"
- /*
- ** Dazzle parsing constants
- */
- const char * HEADLIGHT_NAME_PREFIX = "REN_HEADLIGHT";
- const char * BRAKELIGHT_NAME_PREFIX = "REN_BRAKELIGHT";
- const char * BLINKLIGHT_NAME_PREFIX = "REN_BLINKLIGHT";
- /***********************************************************************************************
- * VehicleDazzleClass::VehicleDazzleClass -- Constructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/27/2001 gth : Created. *
- *=============================================================================================*/
- VehicleDazzleClass::VehicleDazzleClass(void) :
- Type(HEADLIGHT_TYPE),
- Model(NULL),
- BlinkRate(0.0f),
- CreationTime(0)
- {
- }
- /***********************************************************************************************
- * VehicleDazzleClass::~VehicleDazzleClass -- Destructor *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/27/2001 gth : Created. *
- *=============================================================================================*/
- VehicleDazzleClass::~VehicleDazzleClass(void)
- {
- REF_PTR_RELEASE(Model);
- }
- /***********************************************************************************************
- * VehicleDazzleClass::Set_Model -- sets the dazzle model for this object to control *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/27/2001 gth : Created. *
- *=============================================================================================*/
- void VehicleDazzleClass::Set_Model(DazzleRenderObjClass * model)
- {
- REF_PTR_SET(Model,model);
- if (Model != NULL) {
- Type = Determine_Type(model);
- CreationTime = WW3D::Get_Sync_Time();
- }
- }
- /***********************************************************************************************
- * VehicleDazzleClass::Set_Time_Of_Day -- updates any parameters which depend on time of day *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/27/2001 gth : Created. *
- *=============================================================================================*/
- void VehicleDazzleClass::Set_Time_Of_Day(float time)
- {
- }
- /***********************************************************************************************
- * VehicleDazzleClass::Pre_Render_Update -- Update dazzle state prior to rendering *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/27/2001 gth : Created. *
- *=============================================================================================*/
- void VehicleDazzleClass::Pre_Render_Update(VehiclePhysClass * parent)
- {
- WWASSERT(parent != NULL);
- if (Model != NULL) {
-
- switch (Type)
- {
- case HEADLIGHT_TYPE:
- {
- /*
- ** Turn on the headlights if the engine is on
- */
- float intensity = (parent->Is_Engine_Enabled() ? 1.0f : 0.0f);
- Model->Set_Dazzle_Color(Vector3(intensity,intensity,intensity));
- break;
- }
-
- case BRAKELIGHT_TYPE:
- {
- /*
- ** Turn on the brakelights if the engine is on
- ** Make them bright if the vehicle has forward velocity but the controller is pointing backwards
- */
- Vector3 velocity;
- parent->Get_Velocity(&velocity);
- float forward_vel = Vector3::Dot_Product(parent->Get_Transform().Get_X_Vector(),velocity);
- bool controller_back = ((parent->Get_Controller() != NULL) && (parent->Get_Controller()->Get_Move_Forward() < 0.0f));
- bool is_braking = ((forward_vel > 0.0f) && (controller_back));
- float intensity = (parent->Is_Engine_Enabled() ? 1.0f : 0.0f);
- intensity *= (is_braking ? 1.0f : 0.25f);
- Model->Set_Dazzle_Color(Vector3(intensity,intensity,intensity));
- break;
- }
- case BLINKLIGHT_TYPE:
- {
- unsigned int elapsed_time = (WW3D::Get_Sync_Time() - CreationTime) & 0x000003FF;
- Model->Set_Hidden(elapsed_time > 0x0000001FF);
- //Model->Set_Hidden(true);
- break;
- }
- }
- }
- }
- /***********************************************************************************************
- * VehicleDazzleClass::Is_Vehicle_Dazzle -- static function for filtering vehicle dazzles *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/27/2001 gth : Created. *
- *=============================================================================================*/
- bool VehicleDazzleClass::Is_Vehicle_Dazzle(RenderObjClass * obj)
- {
- int type = Determine_Type(obj);
- return type != NONE;
- }
- /***********************************************************************************************
- * VehicleDazzleClass::Determine_Type -- Determine the type of vehicle dazzle this is *
- * *
- * INPUT: *
- * *
- * OUTPUT: *
- * *
- * WARNINGS: *
- * *
- * HISTORY: *
- * 7/30/2001 gth : Created. *
- *=============================================================================================*/
- int VehicleDazzleClass::Determine_Type(RenderObjClass * obj)
- {
- if ((obj != NULL) && (obj->Class_ID() == RenderObjClass::CLASSID_DAZZLE)) {
-
- DazzleRenderObjClass * dazzle = (DazzleRenderObjClass *)obj;
- const char * type_name = DazzleRenderObjClass::Get_Type_Name(dazzle->Get_Dazzle_Type());
-
- if (strnicmp(type_name,HEADLIGHT_NAME_PREFIX,strlen(HEADLIGHT_NAME_PREFIX)) == 0) {
- return HEADLIGHT_TYPE;
- }
-
- if (strnicmp(type_name,BRAKELIGHT_NAME_PREFIX,strlen(BRAKELIGHT_NAME_PREFIX)) == 0) {
- return BRAKELIGHT_TYPE;
- }
- if (strnicmp(type_name,BLINKLIGHT_NAME_PREFIX,strlen(BLINKLIGHT_NAME_PREFIX)) == 0) {
- return BLINKLIGHT_TYPE;
- }
- }
- return NONE;
- }
|