Page 1 of 1
Getting the area of the map in view
Posted: 31 Jul 2012, 14:40
by Beherith
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.
Re: Getting the area of the map in view
Posted: 31 Jul 2012, 15:50
by gajop
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):
[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
Re: Getting the area of the map in view
Posted: 31 Jul 2012, 15:53
by Beherith
I tried using the (true,false,false) argument combo, and my problem was it returning nil when not on map.
Re: Getting the area of the map in view
Posted: 31 Jul 2012, 16:04
by gajop
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.
Re: Getting the area of the map in view
Posted: 31 Jul 2012, 16:07
by Beherith
Re: Getting the area of the map in view
Posted: 31 Jul 2012, 16:31
by gajop
think it may be a problem if you're using corners, try this instead.
Code: Select all
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
Re: Getting the area of the map in view
Posted: 31 Jul 2012, 16:38
by gajop
hmm, although, no, that doesn't always work at some camera angles...
guess you might just need to calculate it based on camera directions