3

I am building a custom map viewer, part of meteorological production system, using Java language and GeoTools library. I have prepared a custom map renderer, using OpenGL, that allows to display maps in different projections and need a bit of help with user camera navigation over maps in Lambert conic projection.

I would like to allow user to navigate the conic map in such way, that map north is always pointing up. Moving mouse left and right should rotate the map around a pole, and moving up/down is always north-south adjustment:

User viewport alignment example

I am struggling with understanding the mathematical transformation for screen-map coordinates for such use case, could anyone point me to the right direction?

This is a code I am trying right now; It only accounts for x axis mouse movement for now:

  • origin vector is north pole location

  • worldPos and prevWorldPos are mouse positions

  • all vectors are in projection coordinate system

    float pdx = prevWorldPos.x - origin.x;
    float pdy = prevWorldPos.y - origin.y;
    
    float radius = (float) Math.sqrt( pdx*pdx + pdy*pdy );
    
    float prevAngle = (float) Math.atan2(pdy, pdx);
    float da = (float) Math.atan2(radius, worldPos.x - prevWorldPos.x);
    
    float angle = prevAngle + da;
    
    cameraAngle = angle+Angles.PI_div_2;
    
    cameraX = origin.x + (float) (radius * Math.cos( angle ));
    cameraY = origin.y + (float) (radius * Math.sin( angle ));
    
  • 1
    Welcome! Please take the community tour: gis.stackexchange.com/tour and edit your question to include details--what software are you using? If building something on your own, what language? Please include what you have tried and specifically what you are struggling with--screen shots and code samples help. – MaryBeth Apr 12 '17 at 12:51
  • please show us what code you have tried already – Ian Turton Apr 12 '17 at 13:13
  • thanks, edited the question... it is about math transformation, disregarding the actual GIS platform. Just a user interaction case – Fima Rotter Apr 12 '17 at 13:18
  • Added some sample code, where I am trying to account only for mouse x axis movement... I feel like I lack the whole transformation understanding, so it may be useless. – Fima Rotter Apr 12 '17 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.