How is it possible for rotating lights attached to objects?
by Anton Bursch · in Torque Game Engine · 05/03/2006 (1:27 am) · 17 replies

How can I set this light which is attached to this player shape to face forward instead of up? I used attachtoobject to attach the light to the player shape. Any ideas?
I tried to change the rotation but it didn't seem to do anything.
%light = new volumeLight() {
dataBlock = "sgMountLight";
//rotation = "-0.357694 0.933839 9.9834e-009 180";
rotation = "0 0 1 0";
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 simply code copied from the swinging light in the TLK demo. Of course that rotation of "0 0 1 0" isn't going to do what I want. That's just there to show where I tried to set rotation at.
The light will rotate with the hand during animations, but it always points up the arm. Any idea how to point it forward like if this was going to be for a flashlight ?
About the author
I design and direct games for Somatic Vision. We primarily make games for use with biofeedback, but our latest game, Tropical Heat, a jet ski racing game, is for regular gamers and is available on PC/Mac and will be available on ipad and iphone soon.
#2
There are two members of the light datablock that control the mount positioning and rotation.
From the Modeler's Guide:
You can use the MountPosition to offset the light in mount space and then the MountRotation is applied (the rotation uses the same scheme as object rotations in the mission editor (xamount, yamount, zamount, rotationangle)).
-John
05/03/2006 (12:07 pm)
Hi Anton,There are two members of the light datablock that control the mount positioning and rotation.
From the Modeler's Guide:
Quote:
The light determines the mount point and offset (both position and rotation) based on the
datablock members MountPoint, MountPosition, and MountRotation.
You can use the MountPosition to offset the light in mount space and then the MountRotation is applied (the rotation uses the same scheme as object rotations in the mission editor (xamount, yamount, zamount, rotationangle)).
-John
#3
05/04/2006 (12:20 pm)
I gave this a try. I set MountRotation, but nothing changes? Can I see an example of how you would use it? I must be doing something wrong the way I am using it. But, I used it just the way the other examples use it. So, I don't understand why it's not working.function addFlashlight()
{
%light = new volumeLight(myVolumeLight) {
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";
MountPoint = "0";
MountPosition = "0 0 0";
MountRotation = "1 0 0 90";
};
%light.attachtoobject(myPlayer); // myPlayer is the name of the player
}
#4
Those are datablock members. I set them up this way so you can create, as an example, a Flashlight datablock that has the rotation and offset built into it, then you can mount a light using the datablock to any object that uses the datablock.
05/04/2006 (1:15 pm)
Hi Anton,Those are datablock members. I set them up this way so you can create, as an example, a Flashlight datablock that has the rotation and offset built into it, then you can mount a light using the datablock to any object that uses the datablock.
#5
05/04/2006 (1:18 pm)
Oh... so... instead of setting the MountRotation in the function like I did, I should set it in the original datablock. Probably copy/paste this datablock and rename it FlashLight or something.
#6
05/04/2006 (3:44 pm)
I got it working now. Thanks so much John. :)
#7
05/04/2006 (3:51 pm)
Glad you got it working...but I have to say that he looks like he has the hand of God!
#8

Now it's working! That's not how it will 'look' in the game, but from my end it's working now. I love this MaleNPC, it's great for working out stuff in a sandbox type area! Man! Now I can spare time for MI3 tonight at 10pm! :)
05/04/2006 (5:07 pm)

Now it's working! That's not how it will 'look' in the game, but from my end it's working now. I love this MaleNPC, it's great for working out stuff in a sandbox type area! Man! Now I can spare time for MI3 tonight at 10pm! :)
#9
05/04/2006 (5:38 pm)
I need one of those cool flashlights for my weapons. On TSE though unfortunately for now :)
#10
could you post your working datablocks for this, I've tried the same thing in the past and I ended up with the same results. My brain isn't absorbing what John explained (which isn't too unusual for me), I kind of grasp it, but I think I learn better visually.
Thanks,
- Alan
05/04/2006 (5:39 pm)
@Antoncould you post your working datablocks for this, I've tried the same thing in the past and I ended up with the same results. My brain isn't absorbing what John explained (which isn't too unusual for me), I kind of grasp it, but I think I learn better visually.
Thanks,
- Alan
#11
Good luck.
And... I can't wait to get TSE/TLK too... I'm just sunk right now because I can't get my lights to work right in TSE and I needed them for a presentation next week. But, I figure, better to use TGE/TLK than nothing at all, so, that's good. My deadline got bumped ahead, so, I ran out of time to work on just lighting in TSE. I can't wait for it to be done though. Literally. :P
05/04/2006 (6:58 pm)
This is the sgMountLight which is what I altered to get the light to rotate the way I wanted. You can see the MountRotation below in bold.//--- OBJECT WRITE BEGIN ---
datablock sgUniversalStaticLightData(sgMountLight) {
className = "sgUniversalStaticLightData";
LightOn = "1";
Radius = "10";
Brightness = "0.988506";
Colour = "1 1 1 1";
FlareOn = "0";
FlareTP = "1";
FlareBitmap = "~/lighting/corona";
FlareColour = "1 1 1 1";
ConstantSizeOn = "0";
ConstantSize = "0.085";
NearSize = "0.085";
FarSize = "0.85";
NearDistance = "3";
FarDistance = "10";
FadeTime = "0.1";
BlendMode = "0";
AnimColour = "0";
AnimBrightness = "1";
AnimRadius = "1";
AnimOffsets = "0";
AnimRotation = "0";
LinkFlare = "1";
LinkFlareSize = "0";
MinColour = "0 0 0 1";
MaxColour = "1 1 1 1";
MinBrightness = "3";
MaxBrightness = "0.988506";
MinRadius = "3";
MaxRadius = "10";
StartOffset = "-5 0 0";
EndOffset = "5 0 0";
MinRotation = "0";
MaxRotation = "359";
SingleColourKeys = "1";
RedKeys = "AZA";
GreenKeys = "AZA";
BlueKeys = "AZA";
BrightnessKeys = "AZA";
RadiusKeys = "AZA";
OffsetKeys = "AZA";
RotationKeys = "AZA";
ColourTime = "3";
BrightnessTime = "3";
RadiusTime = "3";
OffsetTime = "5";
RotationTime = "5";
LerpColour = "1";
LerpBrightness = "1";
LerpRadius = "1";
LerpOffset = "1";
LerpRotation = "1";
StaticLight = "1";
SpotLight = "1";
SpotAngle = "19.4138";
AdvancedLightingModel = "0";
EffectsDTSObjects = "1";
CastsShadows = "1";
DiffuseRestrictZone = "1";
AmbientRestrictZone = "0";
LocalAmbientAmount = "0";
SmoothSpotLight = "1";
DoubleSidedAmbient = "0";
LightingModelName = "SG - Original Stock (Lighting Pack)";
UseNormals = "1";
MountPoint = "0";
MountPosition = "0 0 0";
[b]MountRotation = "1 0 0 20";[/b]
};
//--- OBJECT WRITE END ---This script shows how to set up the light volume to have the flashlight effect I made. I'm sure you can find a prettier way to do it.%light = new volumeLight(myFlashLight)
{
dataBlock = "sgMountLight";
//rotation = "-0.357694 0.933839 9.9834e-009 180";
rotation = "0 0 1 0";
scale = "1 1 1";
dataBlock = "sgMountLight";
Enable = "1";
IconSize = "0.1";
ParticleColorAttenuation = "1";
Texture = "common/lighting/lightFalloffMono.png";
lpDistance = "0.35";
ShootDistance = "15"; // this sets how far the light rays go
Xextent = ".1"; // this sets how focused the light rays are
Yextent = ".1"; // this too
SubdivideU = "10"; // this sets how many light rays you have
SubdivideV = "10"; // this too
FootColour = "1.000000 1.000000 1.000000 0.182000";
TailColour = "0.000000 0.000000 0.000000 0.000000";
};
%light.attachtoobject(myPlayer); // [b]myPlayer[/b] is the player.Let me know if you need any thing else pointed out. I set a lot of the sgMountLight settings in the light editor in the mission editor. But I had to hand adjust the MountRotation and I had to hand adjust the light volume.Good luck.
And... I can't wait to get TSE/TLK too... I'm just sunk right now because I can't get my lights to work right in TSE and I needed them for a presentation next week. But, I figure, better to use TGE/TLK than nothing at all, so, that's good. My deadline got bumped ahead, so, I ran out of time to work on just lighting in TSE. I can't wait for it to be done though. Literally. :P
#12
05/04/2006 (7:23 pm)
@Alan... hey, maybe you could return a favor and email me a copy of tlk with normal mapping. :) That would be real cool. :P
#13
I was just about ready to upload the resource as a TLK private resource, when I discovered it was crashing on exit. If you want all the files up to this point, maybe you can figure them out. Just shout back. I'm in the middle of trying to track down the problem but I'll zip them up and let you have a go at them...it is my current set that includes TLK, cg normal mapping and the water upgrade...Oh what the heck...they're on the way. If you figure anything out make sure you let me know. I still plan to post them as a TLK resource as soon as I figure out the problem.
-Alan
BTW the CG folder goes in the example directory, I didn't make the structure right in the zip. Sorry!
...And you need to follow the instructions for the bumpmapping resource, just use these files for your merge into your build and it should work right...probably...maybe...not a clue...
05/04/2006 (7:54 pm)
@AntonI was just about ready to upload the resource as a TLK private resource, when I discovered it was crashing on exit. If you want all the files up to this point, maybe you can figure them out. Just shout back. I'm in the middle of trying to track down the problem but I'll zip them up and let you have a go at them...it is my current set that includes TLK, cg normal mapping and the water upgrade...Oh what the heck...they're on the way. If you figure anything out make sure you let me know. I still plan to post them as a TLK resource as soon as I figure out the problem.
-Alan
BTW the CG folder goes in the example directory, I didn't make the structure right in the zip. Sorry!
...And you need to follow the instructions for the bumpmapping resource, just use these files for your merge into your build and it should work right...probably...maybe...not a clue...
#14
05/04/2006 (7:57 pm)
WOW!! I give it a look and see if I can figure out what's going on. THANK YOU!!! I was half kidding asking. This is so cool!!! Thank you!!!
#15
- Alan
The crashing was in sceneGraph.cc. I went back through and remerged DRL 2.0 and then did the fix for DRL and the Water Update to work together, I had originally patched sceneGraph.cc wrong. I've sent the updated file.
Edit Again! Nevermind, that file needed correction, but it wasn't the crashing problem. Back to the drawing board.
And Again. winGL.cc not exact, not the problem, but I'm thinking it's not resource related. I jumped back one build, added in the resources again, brought in the current content and with the exception of some lighting lock ups(resolved with removing and adding back in the lights) it doesn't crash. I'm firing off that file to you also.
05/04/2006 (8:03 pm)
Don't get caught up messing with it and miss your movie!- Alan
The crashing was in sceneGraph.cc. I went back through and remerged DRL 2.0 and then did the fix for DRL and the Water Update to work together, I had originally patched sceneGraph.cc wrong. I've sent the updated file.
Edit Again! Nevermind, that file needed correction, but it wasn't the crashing problem. Back to the drawing board.
And Again. winGL.cc not exact, not the problem, but I'm thinking it's not resource related. I jumped back one build, added in the resources again, brought in the current content and with the exception of some lighting lock ups(resolved with removing and adding back in the lights) it doesn't crash. I'm firing off that file to you also.
#16
Hey John, how's it going? Thought I'd dredge up this thread since I have a question about it. Can I mount a light to let's say a weapon object, then mount that object to the player's mount point? I've created a flashlight that's in the weapons class and I've been able to mount the light to it with the proper rotation, but when the player picks it up, the flashlight goeswith the player, but the light stays behind.
(I see, btw further up an example you gave, but I think my mind is mush at the moment).
Thanks for any input!
- Alan
05/22/2006 (8:12 pm)
@John K.Hey John, how's it going? Thought I'd dredge up this thread since I have a question about it. Can I mount a light to let's say a weapon object, then mount that object to the player's mount point? I've created a flashlight that's in the weapons class and I've been able to mount the light to it with the proper rotation, but when the player picks it up, the flashlight goeswith the player, but the light stays behind.
(I see, btw further up an example you gave, but I think my mind is mush at the moment).
Thanks for any input!
- Alan
#17
Shape base objects mount shape images (which are datablocks) instead of other shape base objects, so unfortunately that won't work, but you can mount the light to the player's mount node and use the offset and transform to adjust the light to just in front of the mounted light (see above for details).
Btw: feel free to email me, just wondering if you received any info back on our conversation last week.
05/23/2006 (1:30 am)
Hi Alan,Shape base objects mount shape images (which are datablocks) instead of other shape base objects, so unfortunately that won't work, but you can mount the light to the player's mount node and use the offset and transform to adjust the light to just in front of the mounted light (see above for details).
Btw: feel free to email me, just wondering if you received any info back on our conversation last week.
Torque Owner Anton Bursch