• Minimap
    22 replies, posted
I am trying to make a minimap and a map vgui for my GPS system. Currently I am running into a problem though. The one major problem I found is that render.RenderView DESTROYS your FPS. A solution I found that most other games use is a map image. Basically its just an image of the map with some math and scaling. I am wondering though how would I go about making the map and scaling it properly for a minimap and menu? I know other servers have done this but their code is obviously private. Thanks
Get world coordinates by pressing a map?
I wish I knew how to read C++. I can only understand bits and peices of it.
Here's a Lua version that I commented to understand what's happening: local pi = math.pi local tau = pi * 2 local Vector = Vector local math_cos = math.cos local math_rad = math.rad local math_sin = math.sin local math_atan = math.atan local math_sqrt = math.sqrt -- Translates a world position to a square 2D area -- Positions outside of the panel are put on the edge -- vOrigin: Radar origin (centre object's position) -- vLocation: Offset position (other object's position) -- flRot: Radar rotation in degrees (centre object's yaw rotation) -- flRadius: Radius of the radar (radar_width / 2) -- Returns a vector with local x/y coordinates on the radar and a z coordinate that equates to the distance from the origin -- Example usage: WorldToRadar(pLocalPlayer:GetPos(), pOtherPlayer:GetPos(), pLocalPlayer:EyeAngles()[2], pRadar:GetWide() / 2) -- Adapted from https://github.com/VSES/SourceEngine2007/blob/master/se2007/game/client/cstrike/hud_radar.cpp#L198-L245 local function WorldToRotated2D(vOrigin, vLocation, flRot, flRadius) -- Translate desired world location in reference to the origin local x = vLocation[1] - vOrigin[1] local y = vLocation[2] - vOrigin[2] local flOffset = math_atan(y/x) -- Move the offset to the correct quadrant if (x < 0) then flOffset = pi + flOffset elseif (y < 0) then flOffset = tau + flOffset end -- flRot is in degrees, flOffset is in radians -- Translate everything to radians flOffset = math_rad(flRot) - flOffset local flDist = math_sqrt(x * x + y * y) -- Find rotated position x = flDist * math_sin(flOffset) y = -flDist * math_cos(flOffset) // The dot is out of the radar's range.. Scale it back so that it appears on the border if (flDist > flRadius * 32) then local flScale = flRadius / flDist x = x * flScale y = y * flScale else x = x / 32 y = y / 32 end -- x/y were calculated independently of the radius, add it back in return Vector(flRadius + x, flRadius + y, vLocation[3] - vOrigin[3]) end
That makes a lot more sense to me. Thanks very much! Are there any good resources for me to start learning C++ and to start understanding source's C++ code?
There's a minimap addon on the workshop that does exactly what you want. Download that and learn from it's code.
There's lots of tutorial videos, books, and documents out there for learning C++ - I personally haven't read too many but I found this one to be extremely straight-forward. Read this page for mini-map generation instructions.
Yeah I realised lol Steam Workshop
Thanks for the link but I tried that before and it would only render a certain part of the map. The map to trace the ends of the map was broken and when trying to contact the author, they said they were no longer intereted in supporting the addon. I tried giving the code a look but it is way too complicated.
It worked for the few maps I tested it with. Nonetheless it has the RenderView code you're looking for at least.
yea it doesn't seem to work with Rockford V2b. Trying some hacky code to try and get it to work. What maps did it work with you? Maybe it is jsut me
If that's the only map you're going to stick with you can probably just hardcode the vectors for the map borders.
I found the problem with using the code is that rp_rockford is optimized to the point where when you try to render the whole map, it doesn't render everything due to optimization. Any way to work around this?
mat_leavis 3
Just seems to draw all the visleafs as a wireframe. Also that command didn't work, I think you meant "mat_leafvis"
Yeah, I remembered the command incorrectly. I can't find a different command that will draw all leaves, so you might have to use AddOriginToPVS in occluded areas.
Tried but it still didn't work. It is slowly fading visleafs away, not unloading them:
Seemingly works for me: Above ground is completely rendered even while underground. Make sure you're adding all the PVS origins in a SetupPlayerVisibility hook.
Would you happen to share your code with me?
-- Add map positions here (use the getpos console command) -- mat_visleaf can show what visleafs are visible in a certain area local tNodePositions = { Vector(1, 2, 3), Vector(-3, -2, -1), } local iNodePositions = #tNodePositions local AddOriginToPVS = AddOriginToPVS hook.Add("SetupPlayerVisibility", "PVSNodes", function() for i = 1, iNodePositions do AddOriginToPVS(tNodePositions[i]) end end)
Tried but it still didn't work I don't know what is wrong with this timer.Create("somevis", 4, 0, function()   print("inside")   local tNodePositions = {   Vector(-6658.854492, 2252.501221, 171.764893),   Vector(-3, -2, -1),   }   local iNodePositions = #tNodePositions   local AddOriginToPVS = AddOriginToPVS   hook.Add("SetupPlayerVisibility", "PVSNodes", function()   for i = 1, iNodePositions do   AddOriginToPVS(tNodePositions[i])   end   end) end) timer.Start("somevis")
Why are you doing that in a timer? Are you running the code serverside?
Yes, just for extra precaution I put the timer there to make sure it is constantly adding it to my PVS
Sorry, you need to Log In to post a reply to this thread.