Showing saved ingame player coordinates in minimap image at website. Problems with scaling/origin.

SintSint Join Date: 2007-01-09 Member: 59540Members, Squad Five Blue
edited March 2013 in Modding
So we have over 100 M rows of hit damage information on ns2stats database and finally started to try and make something out of it.
I made simple command to upload map based data from lua to ns2stats.org database so it (should be) simple to scale and offset coordinates for every map's minimap correctly.
This data contains:
//File GUIminimap.lua
     local plottedX = (posX + self.plotToMapConstX) * self.plotToMapLinX
     local plottedY = (posZ + self.plotToMapConstY) * self.plotToMapLinY        

    local values = {               
        plotted_x = plottedX,
        plotted_y = plottedY,
        plotToMapConst_x = self.plotToMapConstX,
        plotToMapConst_y = self.plotToMapConstY,
        plotToMapLin_X = self.plotToMapLinX,
        plotToMapLin_Y = self.plotToMapLinY,
        backgroundWidth = GUIMinimap.kBackgroundWidth,
        backgroundHeight = GUIMinimap.kBackgroundHeight,    
        scaleX =Client.minimapExtentScale.x,        
        scaleY =Client.minimapExtentScale.y,        
        scaleZ =Client.minimapExtentScale.z,        
        originX =Client.minimapExtentOrigin.x,        
        originY =Client.minimapExtentOrigin.y,        
        originZ =Client.minimapExtentOrigin.z,                        
    }

uploadToNs2stats(values,mapname)

Using this above data and some convert functions, data will be quite accurately shown for ns2_summit: (data contains one round rifle hits and skulk bites)
ns2summitdata.jpg
http://dev.ns2stats.org/round/round/63264

Convert functions are following:
  this.convXtoCvsX = function (x)
    {
        x = x/(this.data['scaleX']/2) * this.cvs.width; //canvas width/minimap image width
        x -=this.data['originX'];
        
        x+=-this.data['backgroundWidth'];
        x+=512; //set origin to center in canvas image/minimap image
        
        return x;
    }

 this.convZtoCvsY = function (y)
    {

        y = y*-1;        //mirror z/y axis

        y = y/(this.data['scaleZ']/2) * this.cvs.height;

        y -=this.data['originZ'];

        y +=this.data['backgroundHeight'];

        y +=512

        return y;
    }

So like seen on image; values which are uploaded for summit work with those convert functions. Problem comes with all other maps, they have wrong scaling or offset even when using every map's own uploaded values. So basically convert function values just happened to work for ns2_summit I guess and coordinates should be converted in different way.

So does anyone have any ideas what data is needed to convert those coordinates into website minimap image and how to do it?

Other examples:
Mineshaft: (wrong scaling+offset?)
ns2mineshaftdata.jpg
http://dev.ns2stats.org/round/round/63262

Tram: http://dev.ns2stats.org/round/round/63271
Docking: http://dev.ns2stats.org/round/round/63281

Image which i am using on website is same image than ingame, only converted to png from tga.

Comments

  • RioRio Join Date: 2005-01-28 Member: 38716Members
    I just did a quick search and found those things which might be interesting to you:

    Client.lua: Line 237-244:
    elseif className == "minimap_extents" then
    

    GUIMinimap.lua: Line 890-918:
    function GUIMinimap:SetScale(scale)
    

    Line 110-119:
    local function PlotToMap(self, posX, posZ)
    
  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    I think the problem is that the scale of the minimap_extents differs on every map.
  • SintSint Join Date: 2007-01-09 Member: 59540Members, Squad Five Blue
    edited March 2013
    JimWest wrote: »
    I think the problem is that the scale of the minimap_extents differs on every map.
    I am actually using different map specific data for every map. I guess that "uploadToNs2stats(values)" was kind bad, since it did not show that i use map name, edited it now. But yes there are different scales for every map I think too. I could trial/error every map to fit, but that would be pretty pain, map origins/scales can change too when edits happen. And there are 74 maps listed in database :P Ofc some of them are same, only different versions.

    Rio wrote: »
    I just did a quick search and found those things which might be interesting to you:

    Client.lua: Line 237-244:
    elseif className == "minimap_extents" then
    

    GUIMinimap.lua: Line 890-918:
    function GUIMinimap:SetScale(scale)
    

    Line 110-119:
    local function PlotToMap(self, posX, posZ)
    

    That Client.minimapExtentScale and Origin comes from that Client.lua file minimap_extents part actually. And my previous lua code posting is in that PlotToMap function. That setScale function might contain some useful data idd:
           // compute map to minimap transformation matrix
            local xFactor = 2 * self.scale
            local mapRatio = ConditionalValue(Client.minimapExtentScale.z > Client.minimapExtentScale.x, Client.minimapExtentScale.z / Client.minimapExtentScale.x, Client.minimapExtentScale.x / Client.minimapExtentScale.z)
            local zFactor = xFactor / mapRatio
            self.plotToMapConstX = -Client.minimapExtentOrigin.x
            self.plotToMapConstY = -Client.minimapExtentOrigin.z
            self.plotToMapLinX = GUIMinimap.kBackgroundHeight / (Client.minimapExtentScale.x / xFactor)
            self.plotToMapLinY = GUIMinimap.kBackgroundWidth / (Client.minimapExtentScale.z / zFactor)
    

    But gonna look into it more later, off to bed now.
  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    edited March 2013
    You could add a hook at OnMapLoadEntity(className, groupName, values) at Server to get the Extent things,
    so the extents will be saved on every match (or for every map so you don't have to do this manually)

    just something like
        if className == "minimap_extents" then
    
            kMinimapExtentScale = values.scale
            kMinimapExtentOrigin = values.origin
    end
    

    and then save the kMinimap thing
  • SintSint Join Date: 2007-01-09 Member: 59540Members, Squad Five Blue
    edited March 2013
    Still working on this. Currently scaling seems to be correct with all maps using following convert functions:
    y = y*-1;
    y = y/(this.data['backgroundHeight']) * this.cvs.height;
    var plottedY = (y + this.data['plotToMapConst_y']) * this.data['plotToMapLin_Y'];
    
    x = x/(this.data['backgroundWidth']) * this.cvs.width;
    var plottedX = (x + this.data['plotToMapConst_x']) * this.data['plotToMapLin_X'];
    
    BackgroundHeigth and backgroundWidth seems to be same for everymap ( 242.578125 x 242.578125).

    That plottedX+plottedY formula is copied from lua.

    Problem is that after using those values, coordinates are still not correct. And their position varies based on maps. Sometimes x&y needs to be more, sometimes less.

    Examples with map's values from lua.
    summit:
    x is too big, correct with ~ -270
    	"scaleX": 414.36813354492,
    	"originX": 36.088600158691 (same than plotToMapConst_x *-1),
    	"plotToMapLin_X": 1.1708338810938,
    
    
    docking:
    x is little too small, correct with ~ +50	
    	"scaleX": 410, 
    	"originX": 91.346649169922 (same than plotToMapConst_x *-1),
    	"plotToMapLin_X": 1.1833079268293,
    
    tram:
    x is too big, correct with ~ -320
    	"scaleX": 350, 
    	"origin_x": -16.647283554077 (same than plotToMapConst_x *-1),
    	"plotToMapLin_X": 1.3861607142857, 
    
    

    Same problem is on y axis, but i guess it will get solved when x axis gets solved. So any ideas? I might be missing something simple really.

  • MendaspMendasp I touch maps in inappropriate places Valencia, Spain Join Date: 2002-07-05 Member: 884Members, NS1 Playtester, Contributor, Constellation, NS2 Playtester, Squad Five Gold, NS2 Map Tester, Reinforced - Shadow, WC 2013 - Shadow, Retired Community Developer
    edited March 2013
    Nevermind. Should have read the thread carefully before replying :P
  • SintSint Join Date: 2007-01-09 Member: 59540Members, Squad Five Blue
    Got it to work with previous scaling functions and added extra function to calculate distance from ns2 minimap origin to current web image center position after scaling and moved all coordinates by results from that.
    veilx.jpg

    And now to to start working on heatmaps and making round minimaps better...
Sign In or Register to comment.