Wheeledvehicle adding lights to "light" node ...
by Vivek Kambli · in Torque Game Engine · 04/30/2005 (12:32 am) · 16 replies
I have added a "point" light to car with some modification to wheeledvehicle.c /h
My car model do not look nice with "point" light source. I am modifying the code to add spot light for headlight and break lights ...
For this code to work, create a car model with four node ( for lights at headlight and break light position.) Name the nodes as below
light0
light1
light2
light3
And then modify the code ...
---------------------------------------------------------------------------------------------------
Wheeledvehicle.h
---------------------------------------------------------------------------------------------------
find code
after the code add
in struct WheeledVehicleData: public VehicleData {
find
in class WheeledVehicle: public Vehicle find
after the code add
My car model do not look nice with "point" light source. I am modifying the code to add spot light for headlight and break lights ...
For this code to work, create a car model with four node ( for lights at headlight and break light position.) Name the nodes as below
light0
light1
light2
light3
And then modify the code ...
---------------------------------------------------------------------------------------------------
Wheeledvehicle.h
---------------------------------------------------------------------------------------------------
find code
#ifndef _VEHICLE_H_ #include "game/vehicles/vehicle.h" #endif
after the code add
//lights #ifndef _LIGHTMANAGER_H_ #include "sceneGraph/lightManager.h" #endif
in struct WheeledVehicleData: public VehicleData {
find
S32 brakeLightSequence; // Brakes S32 steeringSequence; // Steering animationafter the code add
//lights bool hasLight; F32 lightRadius; ColorF lightColor; VectorF mDirection; //light node S32 lightNode[4];
in class WheeledVehicle: public Vehicle find
Wheel mWheel[WheeledVehicleData::MaxWheels]; TSThread* mSteeringThread;
after the code add
//lights void registerLights(LightManager * lm, bool lightingScene); LightInfo mLight;
#2
05/03/2005 (3:41 am)
Do those lights cast shadows? nice resource by the way
#3

still need some more coding to get it working on diff and terrain ... i will post this as a resource once fully operational ...
05/03/2005 (4:29 am)
No, working on it , just got the spot light working see the snap shot 
still need some more coding to get it working on diff and terrain ... i will post this as a resource once fully operational ...
#4
07/04/2005 (9:33 pm)
The c source the bedspread script which it changes but becomes, when it changes how, it hangs Thank you.
#5
10/10/2005 (6:31 am)
Hi Vikek, Does this work?
#6
from:
#include "sceneGraph/lightManager.h"
to:
#include "lightingSystem/sgLightManager.h"
and from:
lightManager->addLight(&mLight);
to:
lightManager->sgRegisterGlobalLight(&mLight);
additionally, in simBase.h, I removed virtual from the registerLights method to make it compile.
from:
virtual void registerLights(LightManager * lm, bool lightingScene) { }
to:
void registerLights(LightManager * lm, bool lightingScene) { }
10/28/2007 (3:13 am)
To make this compile and work in TGE 1.5.2, I had to change the following: from:
#include "sceneGraph/lightManager.h"
to:
#include "lightingSystem/sgLightManager.h"
and from:
lightManager->addLight(&mLight);
to:
lightManager->sgRegisterGlobalLight(&mLight);
additionally, in simBase.h, I removed virtual from the registerLights method to make it compile.
from:
virtual void registerLights(LightManager * lm, bool lightingScene) { }
to:
void registerLights(LightManager * lm, bool lightingScene) { }
#7
10/28/2007 (8:40 pm)
How did this work for you?
#8
10/29/2007 (6:01 am)
Well I'm still testing it. I had to do the above to make it compile and not complain. I put this in vehicle.h/.cc, and have to find datablocks to make it work. Looks like light to light4 might also have to be capitalized per the dts node listings. I will report on this once I can get ANY lights working in my game.
#9
11/07/2007 (10:14 am)
Have you had any luck with this yet?
#11
11/12/2007 (7:55 pm)
That looks like you just need to make some tweaks to the light object itself. Well I am certainly interested. Did you have to make a lot of changes to the code above?
#12
11/13/2007 (1:07 am)
No, for some reason I decided to restart my code from scratch using TGE 1.5.2/ AFX 1.0.2 as a base, with my engine changes added back in. I compiled, and the bloody thing now works. One problem is that the nodes are not light nodes, but rather standard mount points. I will dig into the lighting code to change it to Light0...Light4, per the docs and the above resource. The above effect is stock, I will change as I tweak it. As soon as I fix the above, I will post it as a resource.
#13
11/13/2007 (1:21 am)
Wow, cool screenie. Looks good.
#14
11/16/2007 (1:01 am)
Update: Added engine glow to engines using lights.
#15
11/23/2007 (6:54 pm)
Nice work. Any luck with shadows?
#16
11/26/2007 (8:08 pm)
I do have a question in regards to this. Are the lights on all of the time? I am asking because I want to make it turn the headlights on and off.
Torque Owner Vivek Kambli
wheeledvehicle.cc
---------------------------------------------------------------------------------------------------
in WheeledVehicleData::WheeledVehicleData() find
after the code add
in bool WheeledVehicleData::preload(bool server, char errorBuffer[256]) find
after the code add
//lights lightColor.clamp(); // resolve light nodes lightNode[0]=-1; lightNode[1]=-1; lightNode[2]=-1; lightNode[3]=-1; lightNode[0]=shape->findNode("light0"); lightNode[1]=shape->findNode("light1"); lightNode[2]=shape->findNode("light2"); lightNode[3]=shape->findNode("light3");in void WheeledVehicleData::initPersistFields() add at the end
in void WheeledVehicleData::packData(BitStream* stream) add at the end
//lights if(stream->writeFlag(hasLight)) { stream->writeFloat(lightRadius/20.0, 8); stream->writeFloat(lightColor.red,7); stream->writeFloat(lightColor.green,7); stream->writeFloat(lightColor.blue,7); }in void WheeledVehicleData::unpackData(BitStream* stream) add at the end
//lights hasLight = stream->readFlag(); if(hasLight) { lightRadius = stream->readFloat(8) * 20; lightColor.red = stream->readFloat(7); lightColor.green = stream->readFloat(7); lightColor.blue = stream->readFloat(7); }in bool WheeledVehicle::onAdd() add before addToScene();
//lights if (mDataBlock->hasLight == true) Sim::getLightSet()->addObject(this);add at the end of file ....
//lights void WheeledVehicle::registerLights(LightManager * lightManager, bool lightingScene) { if(lightingScene) return; if (mDataBlock->hasLight ) { mLight.mType = LightInfo::Spot; mLight.mDirection = mDataBlock->mDirection; //Point3F osp,sp; Point3F osp,sp; if (mDataBlock->lightNode[0] != -1) { mShapeInstance->mNodeTransforms[mDataBlock->lightNode[0]].getColumn(3,&osp); getRenderTransform().mulP(osp,&sp); mLight.mPos = sp; } else getRenderTransform().getColumn(3, &mLight.mPos); mLight.mRadius = mDataBlock->lightRadius; mLight.mColor = mDataBlock->lightColor; lightManager->addLight(&mLight); } }rebuild engine ...
you are done .....