Home   Help Search Login Register  

Author Topic: Relative Position  (Read 1871 times)

0 Members and 1 Guest are viewing this topic.

StonedSoldier

  • Guest
Relative Position
« on: 04 Dec 2004, 13:15:19 »
how would i camcreate an object that is always 8m behind a certain unit, i can do this easily if the unit is pointing exactly north but it doesnt work when its pointing in any other direction
« Last Edit: 04 Dec 2004, 13:17:14 by StonedSoldier »

Offline KTottE

  • Former Staff
  • ****
Re:Relative Position
« Reply #1 on: 04 Dec 2004, 13:22:43 »
You could use the custom function: SetRelPos.
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Relative Position
« Reply #2 on: 04 Dec 2004, 16:15:26 »
These are formulae I use for things like this:

To find the coordinates of a point in front of or to the side of an object

if:
x1,y1 are the coordinates of the object
theta is the direction of the object
d is the distance of the point from the object

then:
For a point in front of the object
X coordinate = x1 + d*sin(theta)
y coordinate = y1 + d*cos(theta)

(for a point behind use -d)


For a point to the right of the object
X coordinate = x1 + d*cos(theta)
y coordinate = y1 - d*sin(theta)

(for a point to the left use -d)

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Relative Position
« Reply #3 on: 04 Dec 2004, 16:18:10 »
whatever = "something" camcreate [(8 * (sin (getdir unit))),(8 * (cos (getdir unit))), (someheight)]
EDIT: see THobson's post below

that will make it always behind the unit, just change someheight to a number, and you can change the distance behind them by changing the 8's to whatever distance

Edit: THobson beat me to it... thats why you don't walk away from your comp for 15 min before posting  ;D
« Last Edit: 05 Dec 2004, 00:25:26 by Triggerhappy »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Relative Position
« Reply #4 on: 04 Dec 2004, 17:36:06 »
Triggerhappy:

You must have been in a hurry - you missed out the coordinates of the object that is having something placed behind it.  I think you meant:

whatever = "something" camcreate [(getPos <object> select 0) - 8 * sin (getdir unit),(getPos <object> select 1) - 8 * cos (getdir unit), (someheight)]


Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Relative Position
« Reply #5 on: 05 Dec 2004, 00:22:19 »
yep, yep, and yep. sorry bout that
(add another yep just to say it)

                         yep

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline XCess

  • Former Staff
  • ****
Re:Relative Position
« Reply #7 on: 08 Dec 2004, 06:29:05 »
YEs maths actually is useful. Go to school kids. DO your homework.

Komuna

  • Guest
Re:Relative Position
« Reply #8 on: 10 Dec 2004, 13:18:47 »
The following functions do exactly what you want: place an object exactly at the relative position [x,y,z], according to the target's direction. It works just like the setCamRelPos, yet you don't need a camera. Therefore, regardless of the target's height, the object will be always placed at the defined relative position.

Code: [Select]
;ECP v1.075 UPDATED FUNCTIONS

;ECP_resources index 32
ECP_getGloPos = {private ["_hgtRef","_altRef","_alt","_ref","_relpos","_ang","_dis","_glopos"]; _ref = _this select 0; _relpos = _this select 1; _altRef = _this select 2; _hgtRef = _this select 3; _ang = getdir _ref + ([[[0,0],_relpos] call ECP_getDirPos); _dis = SQRT(((_relpos select 0)^2)+((_relpos select 1)^2)); _altRef setPos [position _ref select 0,position _ref select 1,0]; _alt = _altRef distance _ref; _glopos = [(position _ref select 0)+_dis*(sin _ang),(position _ref select 1)+_dis*(cos _ang)]; _altRef setPos _glopos + [0]; _hgtRef setPos _glopos; _alt = _alt - (_altRef distance _hgtRef); _glopos + [_alt+(_relpos select 2)+0.381]}

;ECP_resources index 33
ECP_getRelPos = {private ["_hgtRef","_altRef","_alt","_ang","_dis","_ref"]; _ref = _this select 0; _altRef = _this select 2; _hgtRef = _this select 3; _ang = ([position _ref,_this select 1] call ECP_getDirPos) - getDir _ref; _dis = [_this select 1,position _ref] call ECP_distancePos; _altRef setPos [(_this select 1) select 0,(_this select 1) select 1,0]; _hgtRef setPos (_this select 1); _alt = _altRef distance _hgtRef; _altRef setPos [position _ref select 0,position _ref select 1,0]; [_dis*(sin _ang),_dis*(cos _ang), _alt - (_altRef distance _ref) - 0.381]}


The syntax and arguments are:

object setPos ([<target>,<relative position>,<altitude (sea level) reference>,<height reference>] call ECP_getGloPos)

relativePosition = ([<target>,<object's global position>,<altitude (sea level) reference>,<height reference>] call ECP_getRelPos)


The sea level reference and height reference should be, respectively:

_altRef = "emptydetector" createVehicle _
_hgtRef = "logic" createVehicle _


I hope it helps you out.

#EDIT!!!

Doh! Just realised that there are two other funcs that are being used by those two. They are:

//3 - Modified 10/02/04 by MorMel (Komuna) -> "Zero Divisor" error avoided, for MMK functions compatibility

ECP_getDirPos = {private["_from","_to","_y","_return"]; _from = _this select 0; _to = _this select 1; _y = ((_to select 1) - (_from select 1)); _return = ((_to select 0) - (_from select 0)) atan2 (IF (_y==0) THEN {1e-10} ELSE {_y}); if ( _return < 0 ) then { _return = _return + 360 }; _return}

//8

ECP_distancePos = {sqrt( (((_this select 0) select 0)-((_this select 1) select 0))^2 + (((_this select 0) select 1)-((_this select 1) select 1))^2 )}
« Last Edit: 10 Dec 2004, 13:30:17 by Komuna »

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re:Relative Position
« Reply #9 on: 10 Dec 2004, 15:07:14 »
You all do realize this can be done waaaaaaay easier with vectors don't you?

Now for a short intro into Vectors:

with getDir we can get the direction the player faces.

Now what we do is quite simple, we know that a heading of 0 degrees is the same as a vector [0,1,0] and facing 90 degrees is a vector [1,0,0] ... Right now does this look formilliar ... it should, if you payed attention in your math class, you dummies. ;D

We all know sinus & cosinus, don't we?
Thank Maruk for making ofp's sinus & cos functions take degrees!

So we can rewrite every point on a circle around any point (in 2d!) as:

position = [x,y,0] (Let's just stay on the ground for now)
center = c
c = [cx, cy, 0]
alpha = heading.
r = radius = distance from center.

x = cx + r * cos(alpha)
y = cy + r * sin(alpha)

Now that's pretty easy isn't it!

Now for example: We want to find a point with a heading of 180 degrees from us. We want the point to be 8 meters behind us so now we have everything we need:

Our pos = [a,b,c]
heading = 180
distance = 8 (meters behind us).

Thus:
x = a + 8 * cos(180)
y = b + 8 * sin(180)

So the point would be [x,y,z], where Z can be zero, but isn't mandatory.

edit:

Hmm is should read better this has been sayed a couple of times now..  ::)
« Last Edit: 10 Dec 2004, 15:27:14 by MachoMan »
Get those missions out there you morons!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Relative Position
« Reply #10 on: 10 Dec 2004, 16:43:54 »
Quote
Hmm is should read better this has been sayed a couple of times now..
Yes it has.


Quote
x = a + 8 * cos(180)
y = b + 8 * sin(180)
These formulae miss the direction of the original object - also the sin and cos seem to be the wrong way round.  If you look at my first post on this thread you will find formulae that will work for, in front or behind, left or right of an object that is pointing in any direction.  

While I do not support the tone used by XCess in his post above I do find it surprising how much noise this topic has generated.  We are only talking simple trigonometry here.  It is no big deal.

Come on StonedSoldier.  'Solve' this thread quick.
« Last Edit: 10 Dec 2004, 17:18:58 by THobson »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Relative Position
« Reply #11 on: 10 Dec 2004, 17:17:13 »
Okay so the thread is still live.

To be ultra general:

If an object is located at (x1,y1) with direction theta
and you want the coordinates of a point that is a distance d away  at an angle alpha to the direction the object is facing then the formulae are:

x = x1 + d*Sin(theta + alpha)
y = y1 + d*Cos(theta + alpha)

MachMan's idea was fine, he just forgot to include the direction of the original object (and got the sine and cosine the wrong way round)

Now who would like the formulae for Einstein's theory of Special Relativity?
« Last Edit: 10 Dec 2004, 17:23:11 by THobson »

Komuna

  • Guest
Re:Relative Position
« Reply #12 on: 10 Dec 2004, 17:52:00 »
Now who would like the formulae for Einstein's theory of Special Relativity?

Me, me!!!

Notice that my two functions work with coordinates, rather than angles. So, in order to place an object 8 m away and 45 degrees according to the center's heading, you'd just have to sum 45 degrees to your 'theta', while I'd have to send the arguments [8*sin 45,8*cos 45,0], which results into a far more complex code comparing to yours. Therefore, I recommend your method for this specific situation.
« Last Edit: 10 Dec 2004, 17:59:52 by Komuna »

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re:Relative Position
« Reply #13 on: 10 Dec 2004, 18:45:13 »
(and got the sine and cosine the wrong way round)
You might be right, I can never remember weather ofpec uses a right or lefthanded system, it depends: If forward is x, I'm right. If forward is y, I'm wrong.
Get those missions out there you morons!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Relative Position
« Reply #14 on: 10 Dec 2004, 22:43:21 »
MachoMan:
OFP measures angles clockwise from north.  y represents north to south, x represents east to west and the point (0,0) is in the bottom left hand corner of the map.

Komuna:
You asked for it.  I will skip the time dilation and all the early stuff and go straigt to the energy equation.

Energy of an object of mass m traveling at velocity v is:
(m*c^2)/(1-v^2/c^2)^1/2

which expands to :

E = m*c^2 + 1/2*m*v^2 + .... an infinite number of incredibly small terms.

Now I expect to see a mission from you that uses this ;)

« Last Edit: 11 Dec 2004, 13:36:56 by THobson »