
Getting the area of the map in view
Moderator: Moderators
Getting the area of the map in view
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
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):
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
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
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.
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
I tried that: http://imolarpg.dyndns.org/trac/balates ... ua?rev=727[126:165]
Re: Getting the area of the map in view
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
hmm, although, no, that doesn't always work at some camera angles...
guess you might just need to calculate it based on camera directions
guess you might just need to calculate it based on camera directions