View topic - Getting the area of the map in view



All times are UTC + 1 hour


Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: 31 Jul 2012, 13:40 
Moderator
User avatar

Joined: 26 Oct 2007, 15:21
I must be very tired because the solution completely eludes me :( The Spring.GetProjectilesInRectangle ( number xmin, number zmin, number xmax, number zmax ...) function takes a rectangle as input. How do I determine the rectangle of the map in view? I tried with TraceScreenRay, but I cant make it work properly for rotated cameras. Any suggestions/previous implementations greatly appreciated.


Top
 Offline Profile  
 
PostPosted: 31 Jul 2012, 14:50 
Moderator

Joined: 05 Aug 2009, 19:42
Hmm, well Spring.TraceScreenRay works for me, are you passing a "true" parameter to only use ground? You may need to use max/min width/height if it goes off the screen.

Also, it doesn't work with water - it will hit the seabed instead of the waves, but according to jk you can use camera to recalculate that (I haven't done it yet so can't supply code):
Quote:
[02:12] <[LCC]jK> you can recalc waterpos from tracescreenray
[02:13] <[LCC]jK> with Spring.GetCameraDirection()
[02:14] <[LCC]jK> it won't be 100% exact cause tracescreenray use a perscreenpixel direction, but it will give sane results


Top
 Online Profile  
 
PostPosted: 31 Jul 2012, 14:53 
Moderator
User avatar

Joined: 26 Oct 2007, 15:21
I tried using the (true,false,false) argument combo, and my problem was it returning nil when not on map.


Top
 Offline Profile  
 
PostPosted: 31 Jul 2012, 15:04 
Moderator

Joined: 05 Aug 2009, 19:42
http://springrts.com/wiki/Lua_UnsyncedR ... w_Geometry
http://springrts.com/wiki/Lua_ConstGame#Map

if current x & y are > 50% of the current screen sizes than it's max map width & height, otherwise is 0.


Top
 Online Profile  
 
PostPosted: 31 Jul 2012, 15:07 
Moderator
User avatar

Joined: 26 Oct 2007, 15:21
I tried that: http://imolarpg.dyndns.org/trac/balatest/browser/trunk/luaui/widgets/gfx_projectile_lights.lua?rev=727[126:165]


Top
 Offline Profile  
 
PostPosted: 31 Jul 2012, 15:31 
Moderator

Joined: 05 Aug 2009, 19:42
think it may be a problem if you're using corners, try this instead.
Code:
   at, b=Spring.TraceScreenRay(sx / 2,0,true,false,false) --bottom
   if at=='ground' then
      y2=math.min(y2, b[3])
   end
   at, t=Spring.TraceScreenRay(sx / 2,sy-1,true,false,false) -- top
   if at=='ground' then
      y1=math.max(y1, t[3])
   end
   at, l=Spring.TraceScreenRay(0,sy / 2,true,false,false) -- left
   if at=='ground' then
      x1=math.max(x1, l[1])
   end
   at, t=Spring.TraceScreenRay(sx-1,sy / 2,true,false,false) --right
   if at=='ground' then
      x2=math.min(x2, t[1])
   end


Top
 Online Profile  
 
PostPosted: 31 Jul 2012, 15:38 
Moderator

Joined: 05 Aug 2009, 19:42
hmm, although, no, that doesn't always work at some camera angles...
guess you might just need to calculate it based on camera directions


Top
 Online Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.