EnglishGermanFrenchRussianItalianSpanish
Log inRegister
 
[SCR] [LIB] Maths scripts, Mult and 3D Trig
Post new topic Reply to topic
View previous topic :: View next topic
Author Message
s9ilent





Joined: 29 Jun 2005
Posts: 2009 on topic
Location: Galactic Sector ZZ9-Plural Z alpha +10 GMT
Thank you for registering your game
modified
PostPosted: Sun, 11. Jan 09, 01:01    Post subject: [SCR] [LIB] Maths scripts, Mult and 3D Trig Reply with quote Print

Some basic scripts.
Remakes of Cycrow's fixed point multiplication scripts, and my 3D trigonometry scripts.

Cycrow's multi. scripts are designed to keep 1000 point accuracy for the 2nd multiplier onwards.
My trig scripts project a point to the front/top/side of an object, depending on which way its facing.

29/01/2010 8:30 +10 GMT
Download Zip file





To just look at the individual scripts click them below
Integer Maths for multiplying 2, 3 and 4 digits respectively
http://members.optuszoo.com.au/whyisthat/scripts/lib.maths.fixed.multi2.xml
http://members.optuszoo.com.au/whyisthat/scripts/lib.maths.fixed.multi3.xml
http://members.optuszoo.com.au/whyisthat/scripts/lib.maths.fixed.multi4.xml

Returns the up left and in front of THIS (Also available in fwd, up right versions). Project versions also available.
http://members.optuszoo.com.au/whyisthat/scripts/lib.maths.trig.3d.offset.xml
Same as above but for individual directions
http://members.optuszoo.com.au/whyisthat/scripts/lib.maths.trig.up.offset.xml
http://members.optuszoo.com.au/whyisthat/scripts/lib.maths.trig.fwd.offset.xml
http://members.optuszoo.com.au/whyisthat/scripts/lib.maths.trig.right.offset.xml




How the scripts work

Project Scripts: These take the given inputs, and return a position x y z units infront/to the left/ontop of [THIS].
This script has rather obvious uses, get a position infront of my ship, to the right etc. This script can also be used to check if a target is infront/ to the side/ontop of your ship by doing the following:
Get $dist from me to target, project fwd with $dist, $dist2 get distance from target to projection, $ratio = 100 * dist2 / $dist, if ratio > 30, is not in front

Offset Scripts: These scripts return the offsets of the infront/to the right/ontop of [THIS]. i.e. Offset + This.position = Projection.
This script is useful if you want to apply movements to large fleets of ships. (e.g. get fwd offset x y z, for each ship, shipx = shipx + offset x etc.)

Split script. This a 3x3 matrix (essentially returns a fwd, right and up offset separately). This can then be used to project/offset MULTIPLE directions from the same rotational basis, but by using MUCH less CPU.
E.g. suppose you where projecting 10 subsystems around a single ship at a given point in time.
$dist = 1000
$matrix = [THIS]-> call script '...set' $dist = $dist
Then to project co ordinates you would use
$pos = [THIS] -> call script '...set.project' fwd=.... left=.... up=.... dist=$dist matrix = $matrix
And you would do this for each of the 10 subsystems



Last edited by s9ilent on Fri, 29. Jan 10, 11:31; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
ThalonMook





Joined: 03 Feb 2004
Posts: 1243 on topic
Location: Augsburg / Germany
Thank you for registering your game
PostPosted: Thu, 28. Jan 10, 17:45    Post subject: Reply with quote Print

Hi,

at first thx for this libs. I searched for this funktions to use them in one of my projects.

I will use it to get a point in front of a gate and also to get a point right/left and up/down from a ship.

Now I have one problem. The 'lib.maths.trig.3d.offset' will not work.
I changed the script a bit:



Code:

Script lib.maths.trig.fwd.offset
Version: 0
for Script Engine Version: 42

Description
Project Fwd co-ords
Arguments
1: up , Var/Number , 'Up /-down dist'
2: right , Var/Number , 'right /-left dist'
3: forward , Var/Number , 'Forward /-back distance'
4: objekt , Var/Gate , 'Objekt'

Source Text

001   
002   $a = objekt -> get rot alpha
003   $b = objekt -> get rot beta
004   $g = objekt -> get rot gamma
005   
006   $sina =  = fixed sin $a
007   $sinb =  = fixed sin $b
008   $cosa =  = fixed cos $a
009   $cosb =  = fixed cos $b
010   
011   $sina = $sina * 1000 / 65536
012   $sinb = $sinb * 1000 / 65536
013   $cosa = $cosa * 1000 / 65536
014   $cosb = $cosb * 1000 / 65536
015   
016   
017   * Forward projection
018 @ $n = [THIS] -> call script 'lib.maths.fixed.multi3' :  first=$forward  second=$cosb  third=$sina
019   $x = - $n
020 @ $n = [THIS] -> call script 'lib.maths.fixed.multi2' :  first=$forward  second=$sinb
021   $y = $n
022 @ $n = [THIS] -> call script 'lib.maths.fixed.multi3' :  first=$forward  second=$cosa  third=$cosb
023   $z = $n
024   
025   
026   
027   $ret =  array alloc: size=3
028   $ret[0] = $x
029   $ret[1] = $y
030   $ret[2] = $z
031   return $ret


Here I show the forward script but I do the same with the 3d.

I call it so:

Code:

@ |$fw.distance = THIS -> call script 'lib.maths.trig.3d.offset' :  Up /-down dist=0  right /-left dist=0 Forward /-back distance=$dist  Objekt=target.gate


But it will not work.
I also use a ship as argument for 'objekt'

Also I found something when I compare the 3d script an the right script.

The calculation of n is differend in row 054 one time its '$y = $y+$n' and in the right script row 009 '$y = $n'. What is the right one ?

I hope you can help me

Cu Thalon


_________________
[ Produktions Booster V1.03 ][ Kontomanager V1.05 ][ Schiffsausrüstungs Verwaltung 1.0]
[ vAD Addon ] [ OTAS Recycling Werk ] [ Hyperion MKII ]
Back to top
View user's profile Send private message Visit poster's website
s9ilent





Joined: 29 Jun 2005
Posts: 2009 on topic
Location: Galactic Sector ZZ9-Plural Z alpha +10 GMT
Thank you for registering your game
PostPosted: Thu, 28. Jan 10, 21:37    Post subject: Reply with quote Print

In the 3d offset, it should be
y = y + n
(Also by default, my scripts use the [THIS] as the object to be turned, instead of a 4th argument that you've added in, e.g. so I call them as $ship -> call script xxxx, instead of ????-> call script x y z $ship)

The reason for it is that rotations are essentially applied onto each other. (And the order is very important). My formulas are essentially a linear representation of the matrix multiplication of the 3 rotation matricies.




P.S the offset script doesn't not return the position infront of the gate, but returns the offset. i.e. to get the actual position in front of the gate you will need gatex + offsetx, etc.
I think your actually after the projection scripts (these add the actual position, THEN return the number)
e.g.
lib.maths.trig.fwd.project

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
ThalonMook





Joined: 03 Feb 2004
Posts: 1243 on topic
Location: Augsburg / Germany
Thank you for registering your game
PostPosted: Fri, 29. Jan 10, 00:05    Post subject: Reply with quote Print

Oh thx for the fast response.

So I have misunderstood the function of your scripts Smile

But where I can get the 'lib.maths.trig.3d.project' ?

I need this for a script or mod that I'm working on.

For the position in front I have a funktional script now. But It will not work for the right/left and up/down position.

I tested to put +16384 to the alpha from the reference object so that the direction is not forward. This will work if the ref looks to the 0,0,0 position of the sector but not if its truned.

What can I use for this ?

Cu Thalon


_________________
[ Produktions Booster V1.03 ][ Kontomanager V1.05 ][ Schiffsausrüstungs Verwaltung 1.0]
[ vAD Addon ] [ OTAS Recycling Werk ] [ Hyperion MKII ]
Back to top
View user's profile Send private message Visit poster's website
s9ilent





Joined: 29 Jun 2005
Posts: 2009 on topic
Location: Galactic Sector ZZ9-Plural Z alpha +10 GMT
Thank you for registering your game
PostPosted: Fri, 29. Jan 10, 09:35    Post subject: Reply with quote Print

Ok apparently I never finished making all the project scripts before, so I've made some new ones and uploaded them.


I've found the typo in the .right script
It went $x = + $n instead of $x = $n, it should now work.


As for why the .up scripts aren't working... I can't seem to replicate the problem.


I've also included the new .split .split.offset and .split.project
Essentially, if you wanted to do many projections/offsets, to the same ship (which isn't moving between these projections), rather then doing 10x 3d.projections (which is very CPU intensive), it is better to do 1x .split, then use that split result 10x in the .split.offset/.split.project
Split essentially pre calculates a $dist fwd offset, $dist left offset, $dist up offset, and then .split.project/offset just adds the 3 offsets together (ass adding up numbers is far less intensive then doing all the trig functions again)

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
ThalonMook





Joined: 03 Feb 2004
Posts: 1243 on topic
Location: Augsburg / Germany
Thank you for registering your game
PostPosted: Fri, 5. Feb 10, 00:27    Post subject: Reply with quote Print

Hi,

thx for your help.

Now it works perfekt. All directions will work fine.


CU Thalon


_________________
[ Produktions Booster V1.03 ][ Kontomanager V1.05 ][ Schiffsausrüstungs Verwaltung 1.0]
[ vAD Addon ] [ OTAS Recycling Werk ] [ Hyperion MKII ]
Back to top
View user's profile Send private message Visit poster's website
s9ilent





Joined: 29 Jun 2005
Posts: 2009 on topic
Location: Galactic Sector ZZ9-Plural Z alpha +10 GMT
Thank you for registering your game
PostPosted: Thu, 10. Mar 11, 07:37    Post subject: Reply with quote Print

Just found a rather... gaping bug in this script..


(I had never used this particular one and it is almost a direct copy/paste of the one it was derived from)

lib.maths.trig.3d.offset.xml does not actually project forwards...

will fix later

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic Reply to topic
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Control Panel
Login Data
The time now is Wed, 13. Dec 17, 16:53

All times are GMT + 2 Hours


Board Security

Copyright © EGOSOFT 1989-2017
Powered by phpBB © 2001, 2005 phpBB Group
Template created by Avatar & BurnIt!
Debug: page generation = 0.10248 seconds, sql queries = 21