Getting the area of the map in view

Getting the area of the map in view

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Getting the area of the map in view

Post 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.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Getting the area of the map in view

Post 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
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Getting the area of the map in view

Post by Beherith »

I tried using the (true,false,false) argument combo, and my problem was it returning nil when not on map.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Getting the area of the map in view

Post 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.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Getting the area of the map in view

Post 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
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Getting the area of the map in view

Post 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
Post Reply

Return to “Lua Scripts”