Product Chat / Rotate Light?

Author
Message
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 20th Jul 2018 19:14 Edited at: 20th Jul 2018 19:23
Hi all, just trying the latest PP and I thought I'd have a look at the new light system. First thing I wanted to try seems a no go in Lua so far. I can see these commands.

Everything but a rotate by the looks Is this likely to be added later on?

Edit- Just tried a small scene to test more easily. If I rotate the entity it does rotate, but does not display it. Returning to the editor the light has rotated but it's fairly random where it ends up pointing in game and as said does not move. I'm thinking its a performance thing, but not sure why as moving a light must be similar in cost. It may of course been simply missed at this early stage.
SPECS: Ryzen 1700 CPU. Nvidia 970GTX. 16 Gig Memory. Win 10.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th Jul 2018 19:57 Edited at: 20th Jul 2018 19:57
The Lua commands were added before the latest updates, at that time there was no light rotation, now there is someone can add a Lua command to rotate the lights. I would have done so had someone informed me that they were adding directional lights! …. although to be fair at the time I was a bit busy with trucks and motorbikes and cars and fonts and physics stuff and particle control commands …. oh that reminds me I really need to get back to the particles stuff at some point, must stop getting distracted ...
Been there, done that, got all the T-Shirts!
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 20th Jul 2018 21:13
Ah sounds good. I was hoping it would be easy to add, or at least fairly easy
SPECS: Ryzen 1700 CPU. Nvidia 970GTX. 16 Gig Memory. Win 10.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th Jul 2018 22:22
It is, maybe, depending on how it was implemented (I haven't had time to look yet), it's just a matter of finding the time.
Been there, done that, got all the T-Shirts!
PM
Tarkus1971
Audio Media Maker
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: England, UK
Posted: 21st Jul 2018 08:35
I had posted this on GitHub a little while ago, as there is no Lua command to rotate spotlights as yet. Hopefully soon.
Aftershock Quad Core AMD FM2+ 3.5 GHz 8GB Motherboard and Processor, A7700k apu, Asus GT970 STRIX 4gb Nvidia gfx card.
King Korg Synth, Alesis SR18 Drum Machine, Akai MPX8 sample player, Roland Fantom XA Synth, Axus Digital AXK2 Digital Drum Kit, Novation Ultranova Synth, Waldorf Blofeld Synth, Roland D05 Synth Module, Bluedio Victory V Headphones, AKG K141 Studio Headphones, Lenovo Ideapad, with Windows 10 64bit, 8Gb Ram and AMD A10 7th Gen Graphics.
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 21st Jul 2018 09:05 Edited at: 21st Jul 2018 10:55


Edit: Sry, my fault it works.
Ebe Editor Free - Build your own EBE structures with easy and without editing any text files
Thread and Download
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 23rd Jul 2018 00:18
Not tried moving a light yet, but the code is there I jumped straight into rotation and found it missing the code above looks like it simply moves the light up and down? Although this line seems odd to me

x,y,z=GetLightPosition( lightNum )

I would expect 3 lines for that, but if it works, it works
SPECS: Ryzen 1700 CPU. Nvidia 970GTX. 16 Gig Memory. Win 10.
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 23rd Jul 2018 08:26
AmenMoses and I implemented it and talked about it:
https://forum.game-guru.com/thread/219877#msg2603348
and here is AmenMoses script:
https://forum.game-guru.com/thread/219877#msg2603365

Like we said there, the spotlight angle is calculated as a vector!!!
Ebe Editor Free - Build your own EBE structures with easy and without editing any text files
Thread and Download
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 23rd Jul 2018 09:11
@DVader: Lua functions can take any number or arguments and return any number of results.
Been there, done that, got all the T-Shirts!
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 23rd Jul 2018 22:40
I'm getting too old that does not compute for me lol.
SPECS: Ryzen 1700 CPU. Nvidia 970GTX. 16 Gig Memory. Win 10.
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 23rd Jul 2018 22:53
I don't know if these are the new commands or not but they just might be.

Alienware Aurora R7 with SSD 256GB boot drive ( C: ) and a secondary drive ( D: ) that is 2TB
Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz 3.19 with Intel Turbo-burst
Installed RAM 16.0 GB
64-bit operating system, x64-based processor
Windows 10 Home
NVIDIA GeForce GTX 1070 with 8192 MB GDDR5 and 8095 MB shared system memory
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 23rd Jul 2018 23:15
Yep, that's them.

In a lot of languages a function can only return a single value and in many can only be passed a set number of values. Lua does not have this restriction!

For example if I right a function with ( … ) as the parameter list then any number of parameters can be passed in and dealt with, similarly if I say 'return a, b, c' then the function will pass back 3 parameters to the calling routine.

If the calling routine only wants say the last parameter then you can discard the ones you don't need by using '_' for example the function GetObjectPosAng returns both the position and angle of an object (note 'object' not entity so it can return the values for static objects as well) but if you only want the angles you simply discard the extra return values so:

local _, _, _, ax, ay, az = GetObjectPosAng( objectId )

Would result in the Euler angles (in degrees) that describe the current rotation in world axis of the object.

local x, _, z, _, ay, _ = GetObjectPosAng( objectId )

otoh would give you the x & z position plus the y angle component (but be warned that it's a Euler angle, not 0 .. 360! ) which may be all you need to for example use in controlling AI.

This sort of feature makes Lua a hugely powerful yet very compact language and means that it can run blindingly fast for an interpreted language, much faster than similar languages like Python.


Been there, done that, got all the T-Shirts!
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 24th Jul 2018 14:27
Ah yes I see. I must admit I avoid functions at all costs. Still a gosub man lol. Never saw anything that doesn't work with them just fine
SPECS: Ryzen 1700 CPU. Nvidia 970GTX. 16 Gig Memory. Win 10.
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 24th Jul 2018 16:07
DVader wrote: "I must admit I avoid functions at all costs. Still a gosub man lol"


In lua, they are called functions but you can also call them subroutines or procedures. Think of a lua function as a subroutine that you use the gosub command. However, with lua, you don't need to use the gosub command and just use the function name. If you're not passing any values to the function (subroutine) then you are still required to use the parentheses; e.g.


Alienware Aurora R7 with SSD 256GB boot drive ( C: ) and a secondary drive ( D: ) that is 2TB
Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz 3.19 with Intel Turbo-burst
Installed RAM 16.0 GB
64-bit operating system, x64-based processor
Windows 10 Home
NVIDIA GeForce GTX 1070 with 8192 MB GDDR5 and 8095 MB shared system memory
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 24th Jul 2018 16:37
Quote: "Ah yes I see. I must admit I avoid functions at all costs. Still a gosub man lol. Never saw anything that doesn't work with them just fine "


You have a better understanding than me, if it's not html it's greek to me :p
[img]belidos3d.swgrp.co.uk/wp-content/uploads/2016/03/blogo.png[/img]
Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 24th Jul 2018 17:48
Quote: "You have a better understanding than me, if it's not html it's greek to me :p"

I've used functions in the past (AGK, DB Pro) but generally as a glorified subroutine. I also avoid local and global variables etc. Again seems unneeded to me (and they were in speccy basic ) I would be similar with HTML to be honest, I dipped my toes in ages ago, but found there just too many other languages to learn to get much out of it. Plus I could just load up a web design tool and make one a lot faster. HTML never struck me as a proper language, which I suppose it isn't really. I think, lol, been awhile.

I think one area functions fail is calling another from within it. Gosubs on the other hand allow you to call em at any point you wish You just have to make sure you don't get yourself confused when returning

Always nice to know help is at hand to brush up a bit though
SPECS: Ryzen 1700 CPU. Nvidia 970GTX. 16 Gig Memory. Win 10.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jul 2018 19:00
I'll have a word with Lee, see if he'll let me put in a Fortran front end.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 24th Jul 2018 19:14
Quote: "I think one area functions fail is calling another from within it"

uhm if that was true then GG scripts wouldn't work at all seeing as the base scripts are just 3 functions (init, main and exit are all just functions) which you then use to call other functions and commands
the only thing to remember with functions is they are local and will treat all variables as local unless you pass the info in (included in the brackets when calling the function - i.e. (e) is passing in the entity number for each of the 3 functions) or the variable is set as a global... this is both a good and a bad thing depending on how you code.

i will admit that being able to pass multiple values back out of a lua function is so much nicer when you compare it to AGK's limit of 1
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 24th Jul 2018 19:17 Edited at: 24th Jul 2018 19:19
Arrrrgggghhh, Fortran, I haven't heard that name in a long, long time. Please, not that.

Yes, lua allows for nested functions.
Alienware Aurora R7 with SSD 256GB boot drive ( C: ) and a secondary drive ( D: ) that is 2TB
Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz 3.19 with Intel Turbo-burst
Installed RAM 16.0 GB
64-bit operating system, x64-based processor
Windows 10 Home
NVIDIA GeForce GTX 1070 with 8192 MB GDDR5 and 8095 MB shared system memory
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jul 2018 19:38
Eh? You can call other functions from within a function, a function can even call itself! (take a look at the chess script for an example of Lua recursion in action!)

In Lua you can embed a function in a table so you can have your data items and functions all together in one place (commonly called an 'object' ).

Also Lua doesn't care what your programming 'style' is, it will quite happily work procedurally, object orientated, functionally, any way you want to do it really. (google Lua meta-tables, it will do your head in!)


Been there, done that, got all the T-Shirts!
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 24th Jul 2018 20:17
Lol. I stand corrected. Perhaps I'm confusing lua and another language with functions use. I'm only a dabbler, I learn't all my lua stuff mainly by looking at the global and playing with the stuff I know. Very occasionally I look at the online lua manual to find alternate commands of use, but I stick to the built in GG stuff mainly.

You never know I might pick some of this other stuff up eventually I've never used Fortran, wasn't that a really old business language?
SPECS: Ryzen 1700 CPU. Nvidia 970GTX. 16 Gig Memory. Win 10.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jul 2018 20:24
Cobol was the business language, Fortran was more for academic/techy use, stuff like really big telescopes were controlled by it.

Lisp was one of my favourites when younger (when thinking upside down was easier), Pascal, Forth … Ahh those were the glory days.

On my CV I used to have 'Fluent in over 50 languages'.
Been there, done that, got all the T-Shirts!
PM
GraPhiX
Forum Support
19
Years of Service
User Offline
Joined: 15th Feb 2005
Playing:
Posted: 24th Jul 2018 20:41 Edited at: 24th Jul 2018 20:42
Quote: "On my CV I used to have 'Fluent in over 50 languages'."



you mean this one


Welcome to the real world!
Main PC - Windows 10 Pro x64 - Core i7-7700K @4.2GHz - 32GB DDR4 RAM - GeForce GTX 1060-6G 6GB - 1TB NVe SSD
Test PC - Windows 10 Pro x64 - G4400 @3.3GHz - 16GB DDR3 RAM - GeForce GTX 950 2GB - 500GB SSD
Laptop - Helios 300 Predator - i7 7700HQ - 32GB - Nvidia GTX1060 6GB - 525GB M2 - 500 SSD - 17.3" IPS LED Panel - Windows 10 Pro x64

Attachments

Login to view attachments
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 24th Jul 2018 20:45
Quote: "On my CV I used to have 'Fluent in over 50 languages'"

Ye well I know … Judo, Karate, taekwondo, jiu-jitsu... And lots of other oriental words
The only person ever to get all his work done by "Friday" was Robinson Crusoe..
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jul 2018 22:15
Quick drive-by video dump:

Been there, done that, got all the T-Shirts!
PM
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 24th Jul 2018 22:35
Fantastic !!
wish I had your talent .
The only person ever to get all his work done by "Friday" was Robinson Crusoe..
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jul 2018 22:48 Edited at: 24th Jul 2018 23:23
I'd swap it for a body that doesn't groan when it gets up off the sofa.

Script attached:

Attach the script to as many of the searchlight entities in the Classics folder (Modern2 IIRC) you want (change the name of the texture file to _D instead of _d2 to get the _I bit to work!)

Then also attach the script to an equal amount of 'lights' set to spotlight mode, place them in the same place on the map as the searchlights.

Voila'
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
synchromesh
Forum Support
10
Years of Service
User Offline
Joined: 24th Jan 2014
Location:
Posted: 24th Jul 2018 23:00
Quote: "I'd swap it for a body that doesn't groan when it gets up off the sofa. "

I would but mines not much better these days
Thanks for the script though ..
The only person ever to get all his work done by "Friday" was Robinson Crusoe..
PM
Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 24th Jul 2018 23:05
Looking great.
So if I want them to be at an angle like yours in the video, I would need to attach the light to a rotated object?

Tried to make the spot light spin other then horizontal y, just by itself, and was getting no luck.

This is my attempt at understanding this.



Still spins only Y rotation for me.
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.

AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jul 2018 23:11 Edited at: 24th Jul 2018 23:14
In my script:
local xv, yv, zv = U.Rotate3D( 0, 0, -1, math.rad( -20 ), angle, 0 )

The -20 is saying rotate downwards around the 'x' axis and the 'angle' is the 'y' axis (which I have already calculated as a radians value by that point).

It is a pretty rough script as if you throw in a 'z' rotation things will get really weird really quickly!

To do this 'properly' would really require using quaternions to make it work at any angle, but for the demo I was knocking up it was sufficient.

The light 'entity' btw is purely a place holder on the map, whatever orientation it is rotated to in the editor will define the 'starting' orientation of the light but when you start using the Lua commands to control the direction of the light then the 'entity' orientation becomes immaterial.
Been there, done that, got all the T-Shirts!
PM
Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 24th Jul 2018 23:19
Ah, I see. Right now if I rotate the light at a 45 degree angle to the horizon at about 8 feet off the ground, it still rotates horizontal to the horizon.

I will post some pictures and a video.

But great work as always. Thanks.
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.

AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jul 2018 23:35
The 'correct' way to do this, i.e. so it will work at any orientation, would be to create a quaternion from the initial Euler angles of the light entity, then rotate that quaternion each frame, convert it back into Euler angles and use those to rotate the light vector.

Would be a lot easier to demonstrate this with a better searchlight model (i.e. one that I can rotate with the light rather than being animated)!

What would be cool would be to have a vehicle mounted searchlight, I could then position this in real time on a moving vehicle and have the 'spotlight' travel with both the vehicle motion and rotate it toward a 'target' at the same time.

One thing I must revisit at some point is a script I wrote way back when I first got the GG bug, the script allowed the player to carry a torch (i.e. with flames not batteries) , but at that time 'dynamic' lights could not be moved, now they can I can breath new life into that script!
Been there, done that, got all the T-Shirts!
PM
Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 25th Jul 2018 01:45
Here is a modified search light with base for a car for testing your scripts.
Nothing special here.
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.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-29 13:20:24
Your offset time is: 2024-03-29 13:20:24