Scripts / Lost in the light

Author
Message
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 2nd Apr 2019 02:45
How to find the light position? Yeah, I know, probably this should be simple.
But I can't decide how to even pull a starter here. Global.lua says;

GetLightPosition : x, y, z = GetLightPosition( lightNum ) -- returns the XYZ position of the dynamic light specified
Is it similar somehow to the g_Entity call? ie;

carx[e] = g_Entity[e]['x']
cary[e] = g_Entity[e]['y']
carz[e] = g_Entity[e]['z']

Help w/ syntax please thanks!
PM
Pirate Myke
Forum Support
14
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 2nd Apr 2019 07:13
RIP
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

New:
Intel(R) Core(TM) i5-8400 CPU @ 2.81GHz, 12GB RAM, Nvidia gtx1050ti 4gb, Windows 10 Home 64bit, Screen resolution 1920 x 1080. System Passmark 3774




AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 2nd Apr 2019 09:03
It's exactly as shown in global.lua, i.e.

local lightNum = GetEntityLightNumber( e )
local x, y, z = GetLightPosition( lightNum )
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Apr 2019 15:23
On the subject amen, how do you recommend using the light angle commands? Is there a way to convert it to Euler? As they seem to be expecting -1 / 1.
I was looking for a way to relate it directly to an entity's angle but that doesn't seem possible?
No big deal if there's not, just thought I would play with it, looks it's one of your additions though, thanks for that
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 2nd Apr 2019 19:38
Quote: "I was looking for a way to relate it directly to an entity's angle but that doesn't seem possible? "

I would like to do with torch too.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 2nd Apr 2019 20:14 Edited at: 2nd Apr 2019 20:15
It's in the script Myke posted, i.e:
local rad = math.rad

local xv, yv, zv = U.Rotate3D( 0, 0, 1 , rad( xA ), rad( yA ), rad( zA ) )
SetLightAngle( light, xv, yv, zv )

It's simply a direction vector so if the light seems to be pointing in a weird direction put the '1' in a different place and try again. (or even use -1 all depends on what the default direction for a spotlight is).
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Apr 2019 20:19
oh of course! works great
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 2nd Apr 2019 20:34
Okay. Thanks guys. That's a new one (this is a new language -to me!)
I'm still in the basics with lua.
Because if you want to get just coordinate Y of light, or just coordinate X
of light (which I'm used to) it didn't look logical in that sense.
This makes sense: local posx, posy, posz = g_PlayerPosX, g_PlayerPosY, g_PlayerPosZ
This didn't make sense: x, y, z = GetLightPosition( lightNum )
I must assume it pulls them separately, it's just new. Thanks for your patience!
I'll find some time to try now!

On the angles-- please let light angle relate to entity angle!!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Apr 2019 21:04
Quote: "On the angles-- please let light angle relate to entity angle!!"

it's fine to convert it like amen posted above... i.e.
Quote: "local rad = math.rad

local xv, yv, zv = U.Rotate3D( 0, 0, 1 , rad( xA ), rad( yA ), rad( zA ) )
SetLightAngle( light, xv, yv, zv )"

where xA, yA, zA are the entity x,y,z angles to pass in
(assumes the light is rotated to face north/forward by default which the GG lights are)

see how this guy has a shoulder torch/light and it follows the monster around the map

lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 3rd Apr 2019 00:08 Edited at: 3rd Apr 2019 00:15
With Lua (and one of the reasons why it is so powerful!) you can pass as many parameters to a function as you like and return as many values as you like.

A few examples :
local xmin, ymin, zmin, xmax, ymax, zmax = GetObjectColBox( obj )

local sx, sy, sz = GetObjectScales( obj )

local x, y, z, xa, ya, za = GetObjectPosAng( obj )

One of the reasons that this is a good thing is that when it comes to performance the bottleneck for Lua is the calling overhead of the interface to C/C++ which is stack based so instead of calling multiple functions to return single values you can instead make a single call and get a bunch of them which reduces that overhead.

Also if you don't actually want all the values, for example maybe we only want the Y scale value for an object, simply replace the ones you don't want with '_' , e.g:

local _, sy = GetObjectScales( obj )

Notice we don't need to specify the '_' for trailing parameters they are discarded by default.

The default way of specifying directional elements in 3D engines is the vector, I added the Rotate3D function to utillib to make it easy to convert between the Euler angle rotational format and vector format. If you specify the x,y,z components in the 0,0,1 format or 1,0,0 or 0,-1,0 then the resulting values you get will be a normalised vector which is what is used in things like light mapping, physics etc.

I strongly suggest getting yourself a good book on math for 3D engines.
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 25th May 2019 04:31
Hmmm... wonderful I guess. I'm just now trying this,
as I've delved into some other things of lately.
So far, no luck, but I keep on trying. The lights just
disappear when I put the below script to them...

I see in Myke's example only this; GetLightPosition( light ) --?? Say what? Where's the variables assigned?
Okay, I'll try something new, just move the light with an existing entity.

local lightNum = GetEntityLightNumber( e )
--local x, y, z = GetLightPosition( lightNum )

function move_light_init(e)
lightNum = GetEntityLightNumber( e )
lightx [lightNum], lighty [lightNum], lightz [lightNum] = GetLightPosition( lightNum )
end

function move_light_main(e)

lightx[lightNum] = lightx[lightNum] + 2
SetLightPosition ( lightNum, lightx[lightNum], lighty[lightNum], lightz[lightNum] )
end
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 25th May 2019 11:47 Edited at: 25th May 2019 11:49
think you mean this
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-12-22 14:09:06
Your offset time is: 2024-12-22 14:09:06