Problem attaching a light to a player
by JohnT · in Torque Game Engine · 04/24/2006 (5:20 pm) · 26 replies
@ John K.,
This is a continuation of a thread that was started in the public forum and is now being moved here.
The problem that I am seeing is if a light is attached to a player, the clients that connect after the server side player is created will not see that player but yet it exists and can be collided with even though it cannot be seen and the light is not visible.
Also, this same behavior can be seen if a StaticShapeData object is created and mounted to the player. Instead of the player disappearing, the StaticShapeData object disappears just as the player did above.
The code that I am using to test this problem for the first scenario is by adding the following to the Crossbow.cs script to mount a light to mount0.
Thanks for the help!
John
function CrossbowImage::onMount(%this,%obj,%slot)
{
// Images assume a false ammo state on load. We need to
// set the state according to the current inventory.
if (%obj.getInventory(%this.ammo))
%obj.setImageAmmo(%slot,true);
%light = new volumeLight() {
dataBlock = "sgMountLight";
rotation = "-0.357694 0.933839 9.9834e-009 180";
scale = "1 1 1";
dataBlock = "sgMountLight";
Enable = "1";
IconSize = "1";
ParticleColorAttenuation = "1";
Texture = "common/lighting/lightFalloffMono.png";
lpDistance = "0.35";
ShootDistance = "5";
Xextent = "0.6";
Yextent = "0.6";
SubdivideU = "4";
SubdivideV = "4";
FootColour = "1.000000 1.000000 1.000000 0.182000";
TailColour = "0.000000 0.000000 0.000000 0.000000";
};
%light.attachtoobject(%obj);
}
This is a continuation of a thread that was started in the public forum and is now being moved here.
The problem that I am seeing is if a light is attached to a player, the clients that connect after the server side player is created will not see that player but yet it exists and can be collided with even though it cannot be seen and the light is not visible.
Also, this same behavior can be seen if a StaticShapeData object is created and mounted to the player. Instead of the player disappearing, the StaticShapeData object disappears just as the player did above.
The code that I am using to test this problem for the first scenario is by adding the following to the Crossbow.cs script to mount a light to mount0.
Thanks for the help!
John
function CrossbowImage::onMount(%this,%obj,%slot)
{
// Images assume a false ammo state on load. We need to
// set the state according to the current inventory.
if (%obj.getInventory(%this.ammo))
%obj.setImageAmmo(%slot,true);
%light = new volumeLight() {
dataBlock = "sgMountLight";
rotation = "-0.357694 0.933839 9.9834e-009 180";
scale = "1 1 1";
dataBlock = "sgMountLight";
Enable = "1";
IconSize = "1";
ParticleColorAttenuation = "1";
Texture = "common/lighting/lightFalloffMono.png";
lpDistance = "0.35";
ShootDistance = "5";
Xextent = "0.6";
Yextent = "0.6";
SubdivideU = "4";
SubdivideV = "4";
FootColour = "1.000000 1.000000 1.000000 0.182000";
TailColour = "0.000000 0.000000 0.000000 0.000000";
};
%light.attachtoobject(%obj);
}
About the author
#2
I have tried the following tests and all done on a clean copy of TGE and TLK.
TGE without TLK
I can create the StaticShapeData Object and mount it to Mount0 without any problem. Also, I checked on the clients and the flashlight appears in every player that is spawned into the world. As a further test I created an instance of the flashlight on the ground and all players saw it the instant it was added to the game. Since mounting of lights is not supported I could not test that part.
TGE with TLK
Once Again I duplicad the above tests and everything worked exactly the same. The flashlight was in everyones hand and I was able to create one on the ground.
Now the problem - When I attach a light to the flashlight, the player appears with the flashlight in hand and any clients that join the game also appear with the flashlight in hand and with the light attached(Server Side). The problem is when I go to the client they see the other player without a flashlight or a light in its hand and only the flashlight appears in the client players hand but no light.
From everything I'm seeing, I believe that there is a problem sending all the light information over to a new connecting client. The shape information appears to go without a problem but everytime the light is attached is where the clients get into trouble and whatever they are attached to dissapears.
Hope this helps,
John T.
04/26/2006 (12:43 pm)
@John K.I have tried the following tests and all done on a clean copy of TGE and TLK.
TGE without TLK
I can create the StaticShapeData Object and mount it to Mount0 without any problem. Also, I checked on the clients and the flashlight appears in every player that is spawned into the world. As a further test I created an instance of the flashlight on the ground and all players saw it the instant it was added to the game. Since mounting of lights is not supported I could not test that part.
TGE with TLK
Once Again I duplicad the above tests and everything worked exactly the same. The flashlight was in everyones hand and I was able to create one on the ground.
Now the problem - When I attach a light to the flashlight, the player appears with the flashlight in hand and any clients that join the game also appear with the flashlight in hand and with the light attached(Server Side). The problem is when I go to the client they see the other player without a flashlight or a light in its hand and only the flashlight appears in the client players hand but no light.
From everything I'm seeing, I believe that there is a problem sending all the light information over to a new connecting client. The shape information appears to go without a problem but everytime the light is attached is where the clients get into trouble and whatever they are attached to dissapears.
Hope this helps,
John T.
#3
04/26/2006 (2:15 pm)
Cool thanks, that gives me some good info to go on - I'll take a look at this.
#4
Is there any way to make the beam stop when it hits an object such as a tree, docks, ...?
Thanks!
05/05/2006 (6:59 am)
One more thing that I am noticing is if I turn the light beam into a laser sight and give it a really long distance that it is passing through all objects in its path.Is there any way to make the beam stop when it hits an object such as a tree, docks, ...?
Thanks!
#5
05/05/2006 (11:36 am)
It's not designed to do that, but you could alter the render code to perform a ray cast for each of the vectors that make up the rays, and clip them to the surfaces they hit.
#6
Thanks!
John
05/05/2006 (12:34 pm)
Are there any areas in the engine that currently perform this function that you can think of? I'll take a look and see if this is something I can tackle.Thanks!
John
#7
The start and end points are in world space, the object mask tells it what type of objects can collide with your ray, and RayInfo returns info about the collision (object, collision point, ...). RayCast returns true if the ray intersects an object.
05/05/2006 (12:45 pm)
Oh ya, forgot to include that - torque has a lot of cool built-in utilities for stuff like this (casting rays, finding objects, ...), for the ray cast try this from within any scene object:RayInfo info; getContainer()->castRay(<start point>, <end point>, <object mask>, &info);
The start and end points are in world space, the object mask tells it what type of objects can collide with your ray, and RayInfo returns info about the collision (object, collision point, ...). RayCast returns true if the ray intersects an object.
#8
So far what I've done is add the following to the light beam rendering inside of RenderGL in VolLight.cc and placed the mask at the top of the file. I am using your swinging light for my testing and trrying to make it stop at the floor.
Most of the time I'm getting a collision point less than 1 unit in the z axis and the beam gets truncated way too short. Am I in the ballpark here or am I way off on this approach?
Thanks,
John T.
06/15/2006 (6:01 am)
Finally got a chance to play with this but am having some difficulty and hope you might point me in the right direction.So far what I've done is add the following to the light beam rendering inside of RenderGL in VolLight.cc and placed the mask at the top of the file. I am using your swinging light for my testing and trrying to make it stop at the floor.
#define MY_OBJECT_MASK (TerrainObjectType | InteriorObjectType | StaticObjectType)
RayInfo info;
Point3F curPos = getRenderPosition(); //get position of light
curPos += Point3F(bx, ay, 0.0f); //Offset from base of light
if(getContainer()->castRay(curPos, curPos+end1, MY_OBJECT_MASK, &info)) //check point for collision
end1 = curPos - info.point; //get the collision point difference to draw with
if(getContainer()->castRay(curPos, curPos+end2, MY_OBJECT_MASK, &info)) //same thing for second point of beam
end2 = curPos - info.point;
//-----------------------------------------------
// Lighting Pack code block
//-----------------------------------------------
sgRenderY(Point3F(bx, ay, 0.0f), end1, end2, mfootColour, mtailColour, k);Most of the time I'm getting a collision point less than 1 unit in the z axis and the beam gets truncated way too short. Am I in the ballpark here or am I way off on this approach?
Thanks,
John T.
#9
The rays are being cast out from curPos in a radial fasion, however the vol light uses a rectangular quad to render the volume, so you need to use the start and end for each of the quad edges that cast out from the light (check out sgRenderY for details, in fact it might be best to do the ray cast in there right before rendering).
The other problem is the cat ray expects world space coords and end is in object space. It looks like you already know that, but adding the render position to end only work if the light isn't rotated. Instead you need to transform it using:
And for the returned point:
These will convert the rays into world space for the ray cast and then convert the intersection point into object space for rendering.
Let me know if this helps!
06/15/2006 (10:44 am)
I see a couple of problems:The rays are being cast out from curPos in a radial fasion, however the vol light uses a rectangular quad to render the volume, so you need to use the start and end for each of the quad edges that cast out from the light (check out sgRenderY for details, in fact it might be best to do the ray cast in there right before rendering).
The other problem is the cat ray expects world space coords and end
// going to world space... getRenderTransform().mulP(start<x>); getRenderTransform().mulP(end<x>);
And for the returned point:
// going to object space... getRenderWorldTransform().mulP(info.point);
These will convert the rays into world space for the ray cast and then convert the intersection point into object space for rendering.
Let me know if this helps!
#10
I'm including one of the methods in case anyone down the road needs to implement this. To save space I am only including the sgRenderY method, the same modifications would need to be made to sgRenderX and make sure to create the mask mentioned earlier.
Thanks Again John!
06/15/2006 (1:46 pm)
That helped tremendously! Got it working now and took your advice and moved everything into sgNewMethods.cc I'm including one of the methods in case anyone down the road needs to implement this. To save space I am only including the sgRenderY method, the same modifications would need to be made to sgRenderX and make sure to create the mask mentioned earlier.
Thanks Again John!
void volumeLight::sgRenderY(const Point3F &near1, const Point3F &far1, const Point3F &far2,
const ColorF &nearcol, const ColorF &farcol, F32 offset)
{
//Copy off our ray points
Point3F nearTest1 = near1;
Point3F farTest1 = far1;
Point3F farTest2 = far2;
// going to world space...
getRenderTransform().mulP(nearTest1);
getRenderTransform().mulP(farTest1);
getRenderTransform().mulP(farTest2);
RayInfo info;
if(getContainer()->castRay(nearTest1, farTest1, MY_OBJECT_MASK, &info))
{
getRenderWorldTransform().mulP(info.point);
farTest1 = info.point;
}
else
farTest1 = far1;
if(getContainer()->castRay(nearTest1, farTest2, MY_OBJECT_MASK, &info))
{
getRenderWorldTransform().mulP(info.point);
farTest2 = info.point;
}
else
farTest2 = far2;
glBegin(GL_QUADS);
glColor4f(nearcol.red, nearcol.green, nearcol.blue, nearcol.alpha);
glTexCoord2f(offset, 0.0);
glVertex3f(near1.x, -near1.y, 0.0f);
glColor4f(nearcol.red, nearcol.green, nearcol.blue, nearcol.alpha);
glTexCoord2f(offset, 0.5);
glVertex3f(near1.x, 0.0f, 0.0f);
glColor4f(farcol.red, farcol.green, farcol.blue, farcol.alpha);
glTexCoord2f(offset, 0.5);
glVertex3f(farTest1.x, 0.0, farTest1.z);
glColor4f(farcol.red, farcol.green, farcol.blue, farcol.alpha);
glTexCoord2f(offset, 0.0);
glVertex3f(farTest1.x, farTest1.y, farTest1.z);
glEnd();
glBegin(GL_QUADS);
glColor4f(farcol.red, farcol.green, farcol.blue, farcol.alpha);
glTexCoord2f(offset, 0.5);
glVertex3f(farTest1.x, 0.0, farTest1.z);
glColor4f(nearcol.red, nearcol.green, nearcol.blue, nearcol.alpha);
glTexCoord2f(offset, 0.5);
glVertex3f(near1.x, 0.0f, 0.0f);
glColor4f(nearcol.red, nearcol.green, nearcol.blue, nearcol.alpha);
glTexCoord2f(offset, 1.0);
glVertex3f(near1.x, near1.y, 0.0f);
glColor4f(farcol.red, farcol.green, farcol.blue, farcol.alpha);
glTexCoord2f(offset, 1.0);
glVertex3f(farTest2.x, farTest2.y, farTest2.z);
glEnd();
}
#11
06/15/2006 (7:14 pm)
Awesome! You should write up a plan showing your results (cool pics always attract attention!). :)
#12
Will do. I think I'll gear it towards implementing a flashlight and a laser pointer using TLK since that is what I'm needing for my game anyway and ever since 1.4 came out the Flashlight Resource for TGE broke.
While I'm working on this topic, any idea why the flashlights don't appear in a networked environment (from original topic in this thread). I'll try and figure it out if you can point me in a general direction again :)
I'm assuming it has to do with the pack/ unpack code and will start there unless you have a different thought.
06/16/2006 (8:06 am)
Thanks John!Will do. I think I'll gear it towards implementing a flashlight and a laser pointer using TLK since that is what I'm needing for my game anyway and ever since 1.4 came out the Flashlight Resource for TGE broke.
While I'm working on this topic, any idea why the flashlights don't appear in a networked environment (from original topic in this thread). I'll try and figure it out if you can point me in a general direction again :)
I'm assuming it has to do with the pack/ unpack code and will start there unless you have a different thought.
#13
My first guess is to verify that the attach code is finding the target object (the player), if not the attach will not happen.
06/17/2006 (12:23 am)
I haven't had time to look at it yet, but I'm hoping to have it in the next release.My first guess is to verify that the attach code is finding the target object (the player), if not the attach will not happen.
#14
The problem is primarily when a new client connects to the session, any players that had lights turned on do not render the player's body or the light. Not exactly sure why this is not a problem with the swinging light.
I'm pretty well stumped on this one and guess I'll need to wait for the next release :(
06/24/2006 (10:33 am)
I'm not having much luck with the last issue. I've verified that the light is attaching without any problems on the clients and if the clients are connected before someone activates a flashlight, they see it without any problems.The problem is primarily when a new client connects to the session, any players that had lights turned on do not render the player's body or the light. Not exactly sure why this is not a problem with the swinging light.
I'm pretty well stumped on this one and guess I'll need to wait for the next release :(
#15
Thanks!
09/12/2006 (4:35 pm)
@John - Just saw that Torque 1.5 is going to be including TLK. Is there any chance that this issue might be resolved in that code base :-). I've been waiting patiently for this feature and am hoping to finally add flashlights to my game.Thanks!
#16
09/13/2006 (4:36 am)
I'm in the process of fixing these problems, once completed I'll roll the changes into TSE, TGE 1.5, and TLK 1.4.2 (basically into all products using the lighting system).
#17
09/13/2006 (4:38 am)
Btw: TSE has true dynamic spotlights that shine on all objects, combined with a volume light it makes a great flashlight.
#18
09/13/2006 (4:53 am)
Thanks John, as always your awsesome!
#19
Edit: are you referring to dynamic lights only being point lights?
09/14/2006 (10:13 am)
@John: what do you mean by 'true dynamic spotlights' and how does that differ from what is currently available with TGE+TLK?Edit: are you referring to dynamic lights only being point lights?
#20
09/14/2006 (12:51 pm)
Yes, the TLK dynamic lights are only point lights. Spotlights, though they work well on DTS objects, require static lighting on interiors and the terrain. One of the first issues I tackled in TSE was dynamic spotlights, so a wider range of effects can be achieved.
Torque Owner John Kabus (BobTheCBuilder)