Jump to content

[SOLVED] Rts Player Questions


photo

Recommended Posts

Hi,

I'll start by saying that I am very new with Unigine, and 3d in general for that matter so I might be going totally in the wrong direction.

 

My high level problem is that I am trying to implement a traditional style rts camera.

1. It should move left, right and up, down based on the proximity of the cursor to screen edges.

2. It should zoom in and out using the wheel following a smooth served path and finally.

3. It should allow for single and multi unit select based on a 2d rectangle drawn in screen.

 

1 and 2 I implemented by controlling a DummyPlayer by monitoring the mouse's x and y in the update function. Is this the correct approach? Would it be more efficient to implement my own player in c++? Is there a callback method I could be using? Is simply calculating the new position and using setPosition on the player correct?

 

3 is more involved, and I've seen folks in here struggle with similar issues.

https://developer.unigine.com/forum/topic/117-how-to-get-frustum-from-a-projection-matrix/?hl=player+frustum#entry587

 

My approach here, like the link above, is to get a 2d rectangle in screen coords, then calculate a sub-frustum of the player's projection and use with getIntersectionNodes.

Is that the recommended way of doing this?

 

Thanks

Jean-Marc

Link to comment

1, 2. Correct. Script performance is enough for this kind of job.

setTransform/setWorldTransform methods are more efficient in compare with setPosition/setWorldPosition, setRotation/setWorldRotation...

Because setPosition|Rotation|Scale methods do matrix decomposition/composition inside the engine code.

 

3. Take look into the data/core/editor/editor_controls.h : 387 file (get_intersection() function).

This function do 2d screen intersection with scene.

Link to comment
×
×
  • Create New...