Developer knowledge network · moderated exchange

UnreliableCode 커뮤니티

개발자 연구, 리버스 엔지니어링 및 코딩 커뮤니티

Knowledge index살다
4Categories
919Threads
2.8K게시물
Guide

CS2 World-to-Screen matrix reading & 3D view projection in Source 2

matrix_math_guy
Math Specialist
MEMBER
대표: 105
가입 날짜: Aug 2018
게시물: 52
감사해요: 41
1개월 전 · Jun 27, 2026 3:09 PM
#1

In Source 2, the ViewMatrix is a 4x4 row-major floating point matrix located at client.dll + dwViewMatrix.

Here is the updated W2S function with behind-camera projection check:

CPP
bool WorldToScreen(const Vector3& world, Vector2& screen, const float matrix[4][4], int width, int height) {
    float w = matrix[3][0] * world.x + matrix[3][1] * world.y + matrix[3][2] * world.z + matrix[3][3];
    if (w < 0.001f) return false; // Target is behind camera view plane

    float x = matrix[0][0] * world.x + matrix[0][1] * world.y + matrix[0][2] * world.z + matrix[0][3];
    float y = matrix[1][0] * world.x + matrix[1][1] * world.y + matrix[1][2] * world.z + matrix[1][3];

    float invW = 1.0f / w;
    screen.x = (width / 2.0f) + (0.5f * x * invW * width + 0.5f);
    screen.y = (height / 2.0f) - (0.5f * y * invW * height + 0.5f);
    return true;
}
vtable_slayer
Senior Reverser
MEMBER
대표: 215
가입 날짜: Mar 2018
게시물: 86
감사해요: 61
1개월 전 · Jun 27, 2026 9:57 PM
#2

Make sure you read the full 64 bytes (sizeof(float) * 16) in a single read call to avoid tearing across render frames.

imgui_artisan
UI Designer
MEMBER
대표: 202
가입 날짜: Apr 2019
게시물: 54
감사해요: 28
1개월 전 · Jun 28, 2026 8:41 PM
#3

Tested at 1440p resolution. Bounding boxes align pixel-perfect over head bones.