1

Topic: HELP NEEDED: Converting MousePos on Screen to position in map

Hello guys,

I'm currently working on a new client. I'd like to create a feature for POIs(Points of interest).
It's working! But I'd also like to set these points with the Crosshair of the client.
For example, I aim somewhere, then I have to press a key, and then there will be rendered an icon.

The problem: I'm not able to convert the mouse position on the screen to a position on a map.


What I've tried:


CNetObj_Character PrevChar = m_pClient->m_Snap.m_aCharacters[0].m_Prev;
CNetObj_Character CurChar = m_pClient->m_Snap.m_aCharacters[0].m_Cur;

vec2 Position = mix(vec2(PrevChar.m_X, PrevChar.m_Y), vec2(CurChar.m_X, CurChar.m_Y), Client()->IntraGameTick());

vec2 MouseOnMap = Position + vec2(m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy].x, m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy].y);


What happens: It outputs that Y is somewhere about 1 Million. X, too. Sometimes X is just Zero.

Can anybody help me, converting the values?

PS: I'm working on the base of DDnet, so don't wonder why there are some differents.

Thanks!

2 (edited by nuborn 2016-01-09 14:38:42)

Re: HELP NEEDED: Converting MousePos on Screen to position in map

This worked for me (in gameclient.cpp)
vec2 MouseOnMap = m_LocalCharacterPos + m_pControls->m_MousePos[g_Config.m_ClDummy];
Now it's possible to write something like m_pEffects->HammerHit(MouseOnMap);

(Edit: fixed it a little)

3 (edited by MetaTee 2016-01-09 16:27:17)

Re: HELP NEEDED: Converting MousePos on Screen to position in map

Edit: Unfortunately it does not work. It outputs values about 1 Million.
Edit2: Im comparing it with the position of my tee.:

CNetObj_Character PrevChar = m_pClient->m_Snap.m_aCharacters[0].m_Prev;
CNetObj_Character CurChar = m_pClient->m_Snap.m_aCharacters[0].m_Cur;

vec2 Position = mix(vec2(PrevChar.m_X, PrevChar.m_Y), vec2(CurChar.m_X, CurChar.m_Y), Client()->IntraGameTick());

The output:

char aBuf[128];
str_format(aBuf, sizeof(aBuf), "X: %d Y: %d", m_pClient->m_MouseOnMap.x, m_pClient->m_MouseOnMap.y);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
str_format(aBuf, sizeof(aBuf), "TEE X: %d Y: %d", CurChar.m_X, CurChar.m_Y);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);

Test 2:
str_format(aBuf, sizeof(aBuf), "DISATANCE: %d ", distance(m_pClient->m_MouseOnMap, Position));
Output is false, too

4

Re: HELP NEEDED: Converting MousePos on Screen to position in map

You have the right position, but the values of vec2 are float, while you print integers (%d). It works if you print with %f or cast to int first.

5

Re: HELP NEEDED: Converting MousePos on Screen to position in map

OMG! Thank you so much! My fault, thought the float value would get rounded up to an integer.