Solved World2Screen issues

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Kroopy

I don't know xxxx :D
Fleep Tier Donator
Nobleman
Jul 25, 2015
19
423
1
Hey guys,

Maybe someone could help me out with this because I've been banging my head against a wall for hours.

Here's a screenshot of the issue I'm having, I'm trying to draw a dot on enemy players, but it is offset up and to the left quite a bit.


I've tried to use two different World2Screen functions and both give the same result.

Here's what I'm working with
C++:
void ESPtest()
{
	for (int i = 1; i < *CurrentGame.num_players; ++i)
	{
		Vec3 enemyPos = *playerArray[i].pos;
		Vec3 myscreen;
	
		float * vMatrix = (float*)0x501AE8;

		WorldToScreen(enemyPos, myscreen, vMatrix);

		//myscreen = W2S(vMatrix, enemyPos);

		glPointSize(4);
		glColor3f(1.0f, 0.0f, 0.0f);
		glBegin(GL_POINTS);
		glVertex2f(myscreen.x, myscreen.y);
		glEnd();

	}
}
C++:
bool WorldToScreen(Vec3 In, Vec3& Out, float * ViewMatrix) {
	Out.x = In.x * ViewMatrix[0] + In.y * ViewMatrix[4] + In.z * ViewMatrix[8] + ViewMatrix[12];
	Out.y = In.x * ViewMatrix[1] + In.y * ViewMatrix[5] + In.z * ViewMatrix[9] + ViewMatrix[13];
	Out.z = In.x * ViewMatrix[2] + In.y * ViewMatrix[6] + In.z * ViewMatrix[10] + ViewMatrix[14];
	float w = In.x * ViewMatrix[3] + In.y * ViewMatrix[7] + In.z * ViewMatrix[11] + ViewMatrix[15];

	if (w < 0.0)
		return false;

	Out.x /= w;
	Out.y /= w;
	Out.z /= w;

	Out.x *= 800.0f / 2.0f;
	Out.x += 800.0f / 2.0f;

	Out.y *= -600.0f / 2.0f;
	Out.y += 600.0f / 2.0f;

	return true;
}

Vec3 W2S(float * ViewMatrix, Vec3 vPlayerLoc)
{

	//Matrix-Vector Product, multiplying world(eye) coordinates by projection matrix = clipCoords
	Vec4 clipCoords;
	clipCoords.x = vPlayerLoc.x*ViewMatrix[0] + vPlayerLoc.y*ViewMatrix[4] + (vPlayerLoc.z)*ViewMatrix[8] + ViewMatrix[12];
	clipCoords.y = vPlayerLoc.x*ViewMatrix[1] + vPlayerLoc.y*ViewMatrix[5] + (vPlayerLoc.z)*ViewMatrix[9] + ViewMatrix[13];
	clipCoords.z = vPlayerLoc.x*ViewMatrix[2] + vPlayerLoc.y*ViewMatrix[6] + (vPlayerLoc.z)*ViewMatrix[10] + ViewMatrix[14];
	clipCoords.w = vPlayerLoc.x*ViewMatrix[3] + vPlayerLoc.y*ViewMatrix[7] + (vPlayerLoc.z)*ViewMatrix[11] + ViewMatrix[15];

	//perspective division, dividing by clip.W = NDC
	Vec3 normalizedDeviceCoordinates;
	normalizedDeviceCoordinates.x = clipCoords.x / clipCoords.w;
	normalizedDeviceCoordinates.y = clipCoords.y / clipCoords.w;
	normalizedDeviceCoordinates.z = clipCoords.z / clipCoords.w;

	//viewport tranform to screenCooords
	GLfloat viewport[4] = { 0 };
	GLfloat depthrange[2] = { 0 };
	glGetFloatv(GL_VIEWPORT, viewport); // viewport = (0, 0, width, height)
	glGetFloatv(GL_DEPTH_RANGE, depthrange); //depthrange = (0,1)

	Vec3 playerScreenCoords;
	playerScreenCoords.x = (viewport[2] / 2 * normalizedDeviceCoordinates.x) + (normalizedDeviceCoordinates.x + viewport[2] / 2);
	playerScreenCoords.y = -(viewport[3] / 2 * normalizedDeviceCoordinates.y) + (normalizedDeviceCoordinates.y + viewport[3] / 2);

	return playerScreenCoords;
}
Using the correct player position offset, my aimbot works perfect so this shouldn't be the issue.
C++:
pos = (Vec3*)(*localPlayerAddress + 0x34);
Don't think I'm missing anything else, but let me know me!
Thanks :)
 
Last edited:

Kroopy

I don't know xxxx :D
Fleep Tier Donator
Nobleman
Jul 25, 2015
19
423
1
Fixed... was missing this stuff

C++:
inline void initGLDraw()
{
    glPushMatrix();
    glViewport(0, 0, *windowWidth, *windowHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, *windowWidth, *windowHeight, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
Thanks Rake :)
 

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
C++:
bool WorldToScreen(Vec3 In, Vec3& Out, float * ViewMatrix) {
    Out.x = In.x * ViewMatrix[0] + In.y * ViewMatrix[4] + In.z * ViewMatrix[8] + ViewMatrix[12];
    Out.y = In.x * ViewMatrix[1] + In.y * ViewMatrix[5] + In.z * ViewMatrix[9] + ViewMatrix[13];
    Out.z = In.x * ViewMatrix[2] + In.y * ViewMatrix[6] + In.z * ViewMatrix[10] + ViewMatrix[14];
    float w = In.x * ViewMatrix[3] + In.y * ViewMatrix[7] + In.z * ViewMatrix[11] + ViewMatrix[15];

    if (w < 0.0)
        return false;

    Out.x /= w;
    Out.y /= w;
    Out.z /= w;

    Out.x *= 800.0f / 2.0f;
    Out.x += 800.0f / 2.0f;

    Out.y *= -600.0f / 2.0f;
    Out.y += 600.0f / 2.0f;

    return true;
}
I just tested this out and it works fine for me.

C++:
        DWORD pEnt = GetClientById(handle, 1);
        DWORD ent = NULL;
        ReadProcessMemory(handle, (LPCVOID)pEnt, &ent, sizeof(ent), NULL);

        vec3 theirPos;
        ReadProcessMemory(handle, (LPCVOID)(ent + 0x34), &theirPos, sizeof(theirPos), NULL);

        float viewMatrix[16];
        DWORD viewMatrixAddy = 0x501AE8;
        ReadProcessMemory(handle, (LPCVOID)viewMatrixAddy, &viewMatrix, sizeof(viewMatrix), NULL);

        vec3 screenPos;
        WorldToScreen(theirPos, screenPos, viewMatrix);

        printf("(%f, %f)\n", screenPos.x, screenPos.y);
I'm getting accurate screen coords using the function. Set a breakpoint and make sure all of your variables are being read fine.
 

Kroopy

I don't know xxxx :D
Fleep Tier Donator
Nobleman
Jul 25, 2015
19
423
1
I've narrowed down the issue to drawing with openGL. I made a bot idle, I centered him on my screen and w2s return an x of 400 which is the center of my 800x600 window. Nevertheless, my red dot is xxxxing off to the left as if it was like x=200.
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods