Results 1 to 9 of 9

Thread: Math problem in menu

  1. #1
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    24
    Thanks
    4
    Thanked 16 Times in 10 Posts

    Question Math problem in menu

    Heya!

    Now it's the third day that I can't solve a menu problem, so it's time to ask for some pro mathematician and menu editors' help.
    So now I'm working on a Call of Duty 4 mod (called APB Mod), and I'm making a 2D map in menu (if anyone is playing APB, it will be something like the respawn-slection menu); and well, I want players to be able to zoom on it, and zoom out. The menu is working fine, except that the zooming is not done linearly. Here is a video about it: Xfire video. The zoom is controlled by a variable, between 0 and 1. The X coordinate is changing based on the percentage of the zoom variable this way:

    100 percent: -99.2
    90 percent: -79.7090
    80 percent: -54.9333
    70 percent: -26
    60 percent: 5.94
    50 percent: 40.5
    40 percent: 77.2
    30 percent: 115.57
    20 percent: 155.37
    10 percent: 196.37
    0 percent: 238.4

    As you can see, the smaller the zoom variable is, the bigger steps will be in the X coordinate.

    So I'd need some help in figuring out, why the hell is it happening.
    Here are the definitions and the map item itself:
    Code:
    #define ZOOM dvarFloat("zoom")
    
    #define placeX(o, q) dvarInt("width") / 2 - (dvarInt("respawn_x") - o) / (20 - ZOOM * 10) - (q)
    #define placeY(o, q) dvarInt("height") / 2 + (dvarInt("respawn_y") - o) / (20 - ZOOM * 10) - (q)
    
    itemDef
    {
    	style			WINDOW_STYLE_SHADER
    	rect			0 0 0 0 HORIZONTAL_ALIGN_NOSCALE VERTICAL_ALIGN_NOSCALE
    	exp				rect X(placeX(0, 512 + ZOOM * 512))
    	exp				rect Y(placeY(0, 256 + ZOOM * 256))
    	exp				rect W(1024 + ZOOM * 1024)
    	exp				rect H(512 + ZOOM * 512)
    	exp				material("lookout_" + dvarString("mapname"))
    	visible			1
    	decoration
    }
    width and height are the resolution of the game (ie 1024 and 768), respawn_x and respawn_y are the origin. Basically it should be broken even if you write 1000 for all the 4 values, since I think the problem is somewhere in the usage of ZOOM. The starting, and the end points are perfect.
    I have tried millions of combinations, but I couldn't get it work. Any ideas are welcome.

    Thank you,
    iCore

    EDIT (07-27 23:13): Viking also checked, and according to him, calculations are fine; so maybe there is an other problem, but still no idea what can be :/
    Last edited by iCore; 27th July 2013 at 21:13.

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    i just put all those values in matlab, looks like this:
    Click image for larger version. 

Name:	plot1.png 
Views:	72 
Size:	8.8 KB 
ID:	358

    Looks like a linear function with some non-linear parts at the end, so i tried a second-order fit, which resulted in this:
    Click image for larger version. 

Name:	plot2.png 
Views:	71 
Size:	9.5 KB 
ID:	359

    Looks alright, doesnt it? Well, when you look at the residue (how much the fit differs from the original) you can see this:
    Click image for larger version. 

Name:	plot3.png 
Views:	71 
Size:	9.4 KB 
ID:	360
    Obviously, there is still a trend in the difference. This means a second-order fit is not enough to describe this function. Looking at a 3rd order didnt change much, but 4th order looks like this:
    Click image for larger version. 

Name:	plot4.png 
Views:	69 
Size:	9.8 KB 
ID:	361

    As you might not want to do 4th order calculations (2nd order was not off by that much), you might wanna stick with 2nd order. Values:
    value = 0.0116*percent^2 - 4.5959 * percent + 240.91

    Good luck

  3. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    iCore (28th July 2013),kung foo man (28th July 2013)

  4. #3
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    24
    Thanks
    4
    Thanked 16 Times in 10 Posts
    Hey, thank you! The diagrams look very meaningful, however I think my math knowledge is under the level, which would be required to understand the 'order calculations' and that 'value' at the end. Can you please make it a little clearer, what is wrong in my definitions? :P

    Thanks your help and your time and sorry for being dumb for it

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Order:
    zero order: y = A
    first order: y = B*x + A
    second: y = C*x^2 + B*x + A
    third: y = D*x^3 + C*x^2 + B*x + A
    etc.

    value is the x-coordinate, so:
    x-coordinate = 0.0116*zoomlevel^2 - 4.5959 * zoomlevel + 240.91

  6. #5
    Private
    Join Date
    Jul 2013
    Posts
    14
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Why do you divide by 'zoom'?

    (dvarInt("respawn_x") - o) / (20 - ZOOM * 10)
    y = 1/x is not a linear function. That's why your zooming is not linear.

  7. The Following User Says Thank You to megazor For This Useful Post:

    iCore (30th July 2013)

  8. #6
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    24
    Thanks
    4
    Thanked 16 Times in 10 Posts
    Thanks for you both!
    IzNoGoD that's probably still a little high for me, but thanks megazor, that's a good idea! Any ideas, how can I make it linear? :P

  9. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Try height = something * (1 - zoom) + something_else.
    Same for width.

  10. The Following User Says Thank You to IzNoGoD For This Useful Post:

    iCore (30th July 2013)

  11. #8
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    24
    Thanks
    4
    Thanked 16 Times in 10 Posts
    I can hardly believe it, but it is working!
    Thanks for both of you
    *.*
    If anyone would have a problem like this, I have solved it this way now: (dvarInt("respawn_x") - o) * (0.05 + (ZOOM * 0.05)).

  12. The Following User Says Thank You to iCore For This Useful Post:

    megazor (31st July 2013)

  13. #9
    Private
    Join Date
    Jul 2013
    Posts
    14
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Now that's a True Sexy Linear Form! Nice one, iCore

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •