Home   Help Search Login Register  

Author Topic: Script not fast enough? (logiccam2)  (Read 1404 times)

0 Members and 1 Guest are viewing this topic.

Offline Blanco

  • Former Staff
  • ****
Script not fast enough? (logiccam2)
« on: 25 Jul 2005, 22:06:18 »
Hi, I'm working on logiccam 2.0 early beta , I've added the ability to pan the camera to an other relative position while the camera is following a moving vehicle.
It still does the job like in logiccam1.0 but this time you can use the normal camsetrelpos values :)

This means you can start the camera behind a moving truck, then the camera catches up and ends in the cargoroom.
It works but it's hard to control the steps the cam has to move each loop.

In theory,...when I want the camera to move 5m up high in 20 seconds,  thats 25cm per second, in a loop with a 0.001s delay that make 0.025m each loop.
But that's theory...

In camsetrelpos therms that's from [0,0,0] to [0,0,5]
On a moving truck the camera stops at aprox 6m high, 1 m too high.
When I use it on a static vehicle the camera moves up to 10m or higher, much to far.

Why is that? It seems to be affected by the vehicle's speed or is my script not fast enough?
 
Anyway, here is the script :

Code: [Select]
;________________________
;::::::::::::::::::::::::
;
;Logiccam2.0
;author <Blanco>
;created 25/06/2005 5:07:54
;________________________
;::::::::::::::::::::::::

_camid = _this select 0
_veh = _this select 1
_campos = _this select 2
_targetpos = _this select 3
_zoom = _this select 4
_dur = _this select 5
_offset = _this select 6
_offset2 = _this select 7

startglcam = true
_cx = _campos select 0
_cy = _campos select 1
_cz = _campos select 2

_tx = _targetpos select 0
_ty = _targetpos select 1
_tz = _targetpos select 2

_fx = _offset select 0
_fy = _offset select 1
_fz = _offset select 2

_ox = _offset2 select 0
_oy = _offset2 select 1
_oz = _offset2 select 2

_q = _dur * (_dur*1.5)

_stepx = _fx / _q
_stepy = _fy / _q
_stepz = _fz / _q

_stepx2 = _ox / _q
_stepy2 = _oy / _q
_stepz2 = _oz / _q

_cgl = "logic" camcreate [0,0,0]
_tgl = "logic" camcreate [0,0,0]


#loop
?!startglcam : goto "endcam"

_cx = _cx + _stepx
_cy = _cy + _stepy
_cz = _cz + _stepz

_tx = _tx + _stepx2
_ty = _ty + _stepy2
_tz = _tz + _stepz2

;player globalchat format ["Rel. Cpl [%1 ,%2 ,%3]       Rel. Tpl [%4 ,%5 ,%6]    %7",_cx,_cy,_cz,_tx,_ty,_tz]

_objx=getpos _veh select 0;
_objy=getpos _veh select 1;
_ang = getdir _veh
_posx=(_cx*cos _ang)+(_cy*sin _ang)+_objx
_posy=(_cy*cos _ang)-(_cx*sin _ang)+_objy

_posx2=(_tx*cos _ang)+(_ty*sin _ang)+_objx
_posy2=(_ty*cos _ang)-(_tx*sin _ang)+_objy


_glpos1=[_posx,_posy,_cz]
_glpos2=[_posx2,_posy2,_tz]

_cgl setpos _glpos1
_tgl setpos _glpos2
_camid camsetpos getpos _cgl
_camid camsettarget _tgl
_camid camsetfov _zoom
_camid camcommit 0

~0.001
?_time < _dur : goto "loop"

#endcam
startglcam = false
@!startglcam
deletevehicle _cgl;deletevehicle _tgl
exit

PARAMS
______

1- Cameraname
2- Name of the vehicle you want to follow
3- Array with the camsetrelpos values for the gamelogic used for the cameraposition. (I've named it camposlogic in logiccam1.0)
4-  Array with the camsetrelpos values for the gamelogic used for the cameratarget. ( Camtargetlogic named in Logiccam1.0)
5- Zoomfactor, same value as Camsetfov
6- Duration, how long will the script run?
7- array offset camposlogic
8- Array offset Camtargetlogic

Full example :
Code: [Select]
[_camera,car,[0,-15,2.5],[0,10,2.5],0.7,20,[0,15,0],[0,0,0]] exec "logiccam2.sqs"
This camera will start 15 meters behind the vehicle, camera pointed to a spot 10m in front the vehicle and 2.5m high.
Then the camera should move 15m forward within 20seconds, like I said, it's not precise it more like 15,5 - 16m

Spoken in camsetrelpos therms :

When your logic starts at [0,-15,2.5] and you offset is [0,15,0], the logic should stop moving at [0,0,2.5]

Other example :

When logic starts at [3,5,0.5], and offset is [-5,2,3], logic should stop at [-2,7,3.5]

You can make complex cutscenes with this, the only thing that should be improved is the accuracy.

Testdemo is coming soon.

*edit*

Damn, I've found a bug when using the script on planes and such...  :-\
I'm sure this is do-able...but I have a bad feeling that I'm still far from the solution


 :P
« Last Edit: 26 Jul 2005, 08:32:18 by Blanco »
Search or search or search before you ask.

Offline .pablo.

  • Former Staff
  • ****
  • When in doubt, empty the magazine.
Re:Script not fast enough? (logiccam2)
« Reply #1 on: 09 Aug 2005, 23:09:32 »
1. since the problem seems to be that the script isn't stopping properly, i suggest you experiment with different end-conditions for the script.  right now, the only way the script seems to end is if startglcam is false (don't know what that is) or if _time is greater than _dur.  maybe add a check of the camera's position relative to the vehicle, that stops the script if it is equal to (or greater than) what it should be.

2. where do you define _time?  is that a default local variable or something?  my initial guess as to what was causing this problem was that the large amount of work you were giving ofp every .001 seconds was reducing the rate at which ofp was able to count time (if ofp does that ???), thus making "ofp time" run slightly slower than "real time", which would cause the script to run longer than it should (as ofp thinks that less time has passed than in reality).  the more the camera had to move, the bigger the error would be, in theory.  i'm assuming a lot in that guess, though, so i could easily be completely wrong. :P

3. are you gonna release that testdemo?  it might help people understand your problem better...
« Last Edit: 09 Aug 2005, 23:12:08 by .pablo. »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Script not fast enough? (logiccam2)
« Reply #2 on: 10 Aug 2005, 15:41:01 »
Quote
2. where do you define _time?
It's 'defined' by OFP ;)
It's a reserved local variable returning the time passed since the script started (in seconds)..

Afaik, if you do define the variable _time yourself, something like _time=2 that overrides the OFP's own definition...
At least people unaware of _time being reserved variable use and define it themselves and the scripts run without probs...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline .pablo.

  • Former Staff
  • ****
  • When in doubt, empty the magazine.
Re:Script not fast enough? (logiccam2)
« Reply #3 on: 10 Aug 2005, 20:55:08 »
Quote
It's 'defined' by OFP ;)
It's a reserved local variable returning the time passed since the script started (in seconds)..

yeah, that's what i figured

Offline Blanco

  • Former Staff
  • ****
Re:Script not fast enough? (logiccam2)
« Reply #4 on: 12 Aug 2005, 13:44:25 »
Thanks for your interest.

Quote
...maybe add a check of the camera's position relative to the vehicle, that stops the script if it is equal to (or greater than) what it should be.

Yes, that was my idea too, but it won't give the user the choice how fast or slow that must happen.
Quote
It's 'defined' by OFP
It's a reserved local variable returning the time passed since the script started (in seconds)..

Yup, I'm using _time to avoid lag issues. The script exits exactly at the given time but it seems that the camera doesn't reach (or moves way to far) the desired position when the vehicle is moving or standing still.
It looks like the whole thing is affected by the vehicle's speed.
Startglcam is a bolean to stop the script before the cam gets in the right postion.
I thought it could be usefull.
Quote

3. are you gonna release that testdemo?  it might help people understand your problem better...

I dropped it, but I see what I can do.
« Last Edit: 16 Aug 2005, 16:11:35 by Blanco »
Search or search or search before you ask.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Script not fast enough? (logiccam2)
« Reply #5 on: 13 Aug 2005, 13:56:23 »
placing the loop segment in an .sqf as a linear run may be another option and then instead of running the code in a loop, just call the .sqf every 0.x seconds by having the call command in the loop

that would certainly speed the system up.

sucha short  delay between calls may cause lag though
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Mikero

  • Former Staff
  • ****
  • ook?
    • Linux Step by Step
Re:Script not fast enough? (logiccam2)
« Reply #6 on: 15 Aug 2005, 03:07:25 »
whenever you goto a #label the ENTIRE script is re-interpreted from the top line. (note, not re-read, re-interpreted)

thus, in your script, considerable crunch is spent on useless initialise statements that wont in fact 'happen' on each loop, only at beginning.

As spaghetti as it looks, you will get some measurable improvement by doing this:

goto initialise

#loop
.......

goto loop

#initialise
........

goto loop

there are obvious refinements needed here like exit statements and blah, but I guess you can 'see' the principle involved
Just say no to bugz