Flashlight in 1.3 probs
by Richard O · in Torque Game Engine · 04/07/2005 (8:31 am) · 8 replies
Hi all.
im trying to incorpoate the flashlight tutorial by Robert Brower from the resources into our game but im having problems with errors appearing in the c++ code. iv gotten it down to 8, tho those errors seem to be about variables not being declared or not being part of the shapeBaseImageData file, when i think they are - tho my knowledge of c++ is severly limited. heres the error file that comes up when i compile the HEAD:
=======================================================
--------------------Configuration: Torque Demo - Win32 Release--------------------
Compiling...
shapeImage.cc
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(398) : error C2039: 'maxLightLength' : is not a member of 'ShapeBaseImageData'
../engine\game/shapeBase.h(106) : see declaration of 'ShapeBaseImageData'
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(399) : error C2039: 'relativeLightIntensity' : is not a member of 'ShapeBaseImageData'
../engine\game/shapeBase.h(106) : see declaration of 'ShapeBaseImageData'
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(400) : error C2039: 'relativeLightRadius' : is not a member of 'ShapeBaseImageData'
../engine\game/shapeBase.h(106) : see declaration of 'ShapeBaseImageData'
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(401) : error C2039: 'minLightRadius' : is not a member of 'ShapeBaseImageData'
../engine\game/shapeBase.h(106) : see declaration of 'ShapeBaseImageData'
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(736) : error C2065: 'lightType' : undeclared identifier
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(745) : error C2065: 'mLightOn' : undeclared identifier
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(823) : error C2065: 'lightRadius' : undeclared identifier
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(834) : error C2065: 'lightColor' : undeclared identifier
Error executing cl.exe.
torqueDemo.exe - 8 error(s), 0 warning(s)
=======================================================
if anybody out there who has more knowledge of code than me could help me here, or anybody that got the resource to work in 1.3, could youse show me where im going wrong here? if you got it working in 1.3 could you forward on how you changed the code to make it so? id appreciate any help you can give. the shapeBase.cc, shapeBase.h, and shapeImage.cc files can be found at the addresses below. if you search for 'RFB' you can find where the code changes to the files were made.
http://student.dcu.ie/~connold8/torque/shapeImage.cc
http://student.dcu.ie/~connold8/torque/shapeBase.cc
http://student.dcu.ie/~connold8/torque/shapeBase.h
thanks
im trying to incorpoate the flashlight tutorial by Robert Brower from the resources into our game but im having problems with errors appearing in the c++ code. iv gotten it down to 8, tho those errors seem to be about variables not being declared or not being part of the shapeBaseImageData file, when i think they are - tho my knowledge of c++ is severly limited. heres the error file that comes up when i compile the HEAD:
=======================================================
--------------------Configuration: Torque Demo - Win32 Release--------------------
Compiling...
shapeImage.cc
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(398) : error C2039: 'maxLightLength' : is not a member of 'ShapeBaseImageData'
../engine\game/shapeBase.h(106) : see declaration of 'ShapeBaseImageData'
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(399) : error C2039: 'relativeLightIntensity' : is not a member of 'ShapeBaseImageData'
../engine\game/shapeBase.h(106) : see declaration of 'ShapeBaseImageData'
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(400) : error C2039: 'relativeLightRadius' : is not a member of 'ShapeBaseImageData'
../engine\game/shapeBase.h(106) : see declaration of 'ShapeBaseImageData'
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(401) : error C2039: 'minLightRadius' : is not a member of 'ShapeBaseImageData'
../engine\game/shapeBase.h(106) : see declaration of 'ShapeBaseImageData'
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(736) : error C2065: 'lightType' : undeclared identifier
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(745) : error C2065: 'mLightOn' : undeclared identifier
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(823) : error C2065: 'lightRadius' : undeclared identifier
C:\Torque\Copy of SDK\engine\game\shapeImage.cc(834) : error C2065: 'lightColor' : undeclared identifier
Error executing cl.exe.
torqueDemo.exe - 8 error(s), 0 warning(s)
=======================================================
if anybody out there who has more knowledge of code than me could help me here, or anybody that got the resource to work in 1.3, could youse show me where im going wrong here? if you got it working in 1.3 could you forward on how you changed the code to make it so? id appreciate any help you can give. the shapeBase.cc, shapeBase.h, and shapeImage.cc files can be found at the addresses below. if you search for 'RFB' you can find where the code changes to the files were made.
http://student.dcu.ie/~connold8/torque/shapeImage.cc
http://student.dcu.ie/~connold8/torque/shapeBase.cc
http://student.dcu.ie/~connold8/torque/shapeBase.h
thanks
#2
04/11/2005 (10:53 am)
Have you tried e-mailing Robert Brower nicely about it?
#3
For your problem, it looks like you need to add "dataBlock->" to each of those variables. The problem is happening in the registerWeaponImageLights function right?
So for example you would say
The problem isn't because they aren't part of shapeBaseImageData (they are) it's because in v1.3 the registerMountedLights function seems to have been moved to ShapeBase instead of where it used to be in shapeBaseImageData.
Let me know if it works.
The problem I'm having is getting the lights registered across the network, if anyone knows about that I could really use some help! thanks.
04/13/2005 (4:59 pm)
Robert Brower hasn't responded to any of my e-mails, and I'm having some problems getting the resource to work too. I can help you with your problem though Richard. If you go to the tutorial and scroll down to the bottom a few people have listed the changes they made for getting the flashlight to compile with v.13.For your problem, it looks like you need to add "dataBlock->" to each of those variables. The problem is happening in the registerWeaponImageLights function right?
So for example you would say
dataBlock->lightColor
The problem isn't because they aren't part of shapeBaseImageData (they are) it's because in v1.3 the registerMountedLights function seems to have been moved to ShapeBase instead of where it used to be in shapeBaseImageData.
Let me know if it works.
The problem I'm having is getting the lights registered across the network, if anyone knows about that I could really use some help! thanks.
#4
incidently, im fooling around with adding a toggle switch that switches the light on and off when the user clicks the mouse button, though its a bit buggy at the minute. have to find out where's the best place to rest the code.
ben, if you're reading this, when i use the flashlight, or constantLight, and turn down the sun so its near pitch black, and i look down at the ground, it (the ground) seems to be a bit buggy. it usually happens to adjacent squares when you look at the ground around you. it kind of hard to explain what it looks like, like the ground tile image is replaced by cross-hatching as if it's having problems rendering. take the intensity of the light down to about .3 and increase the radius of the light to about 20 to see what i mean.
thanks
04/14/2005 (5:53 am)
Thanks for that brandon, i got it working, as well as the other lights like ConstantLight and PulsingLight. it's not casting any shadows tho. judging by having to add "dataBlock->" to the rest of the variables, which part of the code covers the shadow bit?incidently, im fooling around with adding a toggle switch that switches the light on and off when the user clicks the mouse button, though its a bit buggy at the minute. have to find out where's the best place to rest the code.
ben, if you're reading this, when i use the flashlight, or constantLight, and turn down the sun so its near pitch black, and i look down at the ground, it (the ground) seems to be a bit buggy. it usually happens to adjacent squares when you look at the ground around you. it kind of hard to explain what it looks like, like the ground tile image is replaced by cross-hatching as if it's having problems rendering. take the intensity of the light down to about .3 and increase the radius of the light to about 20 to see what i mean.
thanks
#5
For me the way I did the switching between flashlight on or off, was to define two weaponImages for each weapon. One with the flashlight, and one withought. Then define a function for both weaponImages, "toggleFalshlight" that unmounts the weapon and puts the other one on the player. And call that function whenever you press a certain key. There's probably a cleaner way to do it, but let me know if you need help with this one.
I was able to fix the flikering lights on the terrain problem by switching the rendering mode to OpenGL, does that help at all?
04/14/2005 (6:08 am)
I'm having problems with the shoadows too, sorry I don't know what to say. You would have had to add "datablock->" more than 8 times though, so you might try undoing some of the other changes you made to get variables known and just add "dataBlock" to them. I can give you a complete list of the variables I put "dataBlock->" in front of if you think it will help? I doubt the shadow problem is there though....For me the way I did the switching between flashlight on or off, was to define two weaponImages for each weapon. One with the flashlight, and one withought. Then define a function for both weaponImages, "toggleFalshlight" that unmounts the weapon and puts the other one on the player. And call that function whenever you press a certain key. There's probably a cleaner way to do it, but let me know if you need help with this one.
I was able to fix the flikering lights on the terrain problem by switching the rendering mode to OpenGL, does that help at all?
#6
It's a shame I'm such a newb at C, this should be easy.
I'm using TGE 1.3 and TLK 1.3.5.
Can someone please post their updated void ShapeBase::MountedImage::registerWeaponImageLights code from shapeImage.cc?
11/25/2005 (8:41 am)
I'm so close, but close isn't enough. :(It's a shame I'm such a newb at C, this should be easy.
I'm using TGE 1.3 and TLK 1.3.5.
Can someone please post their updated void ShapeBase::MountedImage::registerWeaponImageLights code from shapeImage.cc?
#7
01/06/2006 (10:20 am)
*bump*
#8
This isn't with TLK, just stock 1.3 TGE, and with the mPrevObjectId fix Robert Bower later posted (and most of the other fixes) as well -- but it still won't update over the network without removing the checks for lighttype....
04/17/2006 (2:55 am)
For anyone else on the forum trail...This isn't with TLK, just stock 1.3 TGE, and with the mPrevObjectId fix Robert Bower later posted (and most of the other fixes) as well -- but it still won't update over the network without removing the checks for lighttype....
void ShapeBase::MountedImage::registerWeaponImageLights(LightManager * lightManager, bool lightingScene, Container* container, const Point3F &muzzlePoint, const VectorF &muzzleVector, U32 startTime )
{
if(lightingScene)
return;
F32 intensity;
switch(dataBlock->lightType)
{
// RFB ->
case dataBlock->FlashLight:
{
// if the light was pointing at shapebase object and is turned off
// then reset the light direction on the object
Point3F defaultDir(0.57f,0.57f,-0.57f);
if (dataBlock->mLightOn == false)
{/*
if (dataBlock->mPrevObject)
{
dataBlock->mPrevObject->setLightDirection(defaultDir);
dataBlock->mPrevObject = NULL; */
ShapeBase* ptr;
if (dataBlock->mPrevObjectId != -1 && Sim::findObject(dataBlock->mPrevObjectId, ptr))
{
ptr->setLightDirection(defaultDir);
dataBlock->mPrevObjectId = -1;
}
return;
}
//mLight.mPos = muzzlePoint;
mLight.mPos = muzzlePoint + muzzleVector;
mLight.mDirection = muzzleVector;
// if maxLightLength > 0 then we're casting a ray from the light node
// in the model to some point in space in front of the image. The angle
// at which the ray is cast is determined by the muzzleVector. If
// we hit something, then we will adjust the distance at which we
// will register the light.
if (dataBlock->maxLightLength > 0)
{
VectorF scale = mLight.mDirection * dataBlock->maxLightLength;
VectorF endPoint = mLight.mPos + scale;
RayInfo rInfo;
if (container->castRay(mLight.mPos, endPoint,
TerrainObjectType | InteriorObjectType |
PlayerObjectType | StaticShapeObjectType |
VehicleObjectType | VehicleBlockerObjectType |
StaticTSObjectType,
&rInfo) == true)
{
ShapeBase* obj = dynamic_cast<ShapeBase*>(rInfo.object);
S32 objId = rInfo.object->getId();
if (obj)
{
if (objId != dataBlock->mPrevObjectId)
//if (obj != dataBlock->mPrevObject)
{
ShapeBase* ptr;
//if (dataBlock->mPrevObject)
if (dataBlock->mPrevObjectId != -1 && Sim::findObject(dataBlock->mPrevObjectId, ptr))
ptr->setLightDirection(defaultDir);
//dataBlock->mPrevObject->setLightDirection(defaultDir);
obj->setLightDirection(mLight.mDirection);
//dataBlock->mPrevObject = obj;
dataBlock->mPrevObjectId = objId;
}
else
obj->setLightDirection(mLight.mDirection);
}
else
{
ShapeBase* ptr;
//if (dataBlock->mPrevObject) {
// dataBlock->mPrevObject->setLightDirection(defaultDir);
// dataBlock->mPrevObject = NULL;
if (dataBlock->mPrevObjectId != -1 && Sim::findObject(dataBlock->mPrevObjectId, ptr)) {
ptr->setLightDirection(defaultDir);
dataBlock->mPrevObjectId = -1;
}
}
// mLight.mPos = rInfo.point;
mLight.mPos = rInfo.point - mLight.mDirection*0.01;
}
else
{
ShapeBase* ptr;
if (dataBlock->mPrevObjectId != -1 && Sim::findObject(dataBlock->mPrevObjectId, ptr)) {
ptr->setLightDirection(defaultDir);
dataBlock->mPrevObjectId = -1;
/*
if (dataBlock->mPrevObject) {
dataBlock->mPrevObject->setLightDirection(defaultDir);
dataBlock->mPrevObject = NULL; */
}
mLight.mPos = endPoint;
}
}
VectorF distanceVector = mLight.mPos - muzzlePoint;
F32 length = distanceVector.len();
if (dataBlock->relativeLightIntensity)
intensity = 1.0 - length / dataBlock->maxLightLength; // RFB -> intensity relative to distance
else
intensity = 1.0; // RFB-> otherwise always brightest
mLight.mRadius = dataBlock->lightRadius * length / dataBlock->maxLightLength; // RFB -> radius relative to distance
if (mLight.mRadius < dataBlock->minLightRadius) // RFB -> just so it doesn't get too small when in close
mLight.mRadius = dataBlock->minLightRadius;
break;
}
// <- RFB
default:
intensity = 1.0f;
return;
}
mLight.mColor = dataBlock->lightColor * intensity;
mLight.mColor.clamp();
mLight.mType = LightInfo::Point;
mLight.mRadius = dataBlock->lightRadius;
lightManager->addLight(&mLight);
}
// end RFB-style mod
Torque Owner Richard O