Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Apr 2016

    How To Find the ViewMatrix

    This should work for 99% of games. It relies on the fact that the up angle axis has to be between -1 and +1, and you find the variable by searching for those values in cheat engine.

    Another good method is knowing the fact that all graphic related variables are probably declared in the same header file. For instance you know that your game resolution is 800x600. Find where your resolution is stored and search around that memory address for other related variables. You can use any starting point, FOV, resolution, etc...You can then use "What Accesses this address" to find functions that access your FOV or resolution and perhaps they also access the view matrix. Trial and error is big in reversing, especially if you don't have alot of experience.

    In a 3d game the ViewMatrix is an array of 16 floats that defines your location in the world and your current viewport:

    If you want to convert 3d coordinates into 2d coordinates in order to draw on your screen you have to find the ViewMatrix which can be difficult for beginners.

    Upon finding the viewmatrix you must "transform" the coordinates by doing some matrix math outlined in this picture:

    A World to Screen transformation function looks like this:
    bool WorldToScreen(float * mvpmatrix, Vec3D pos, Vec3D &playerScreenCoords)
    	//Matrix-vector Product, multiplying world(eye) coordinates by projection matrix = clipCoords
    	Vec4D clipCoords;
    	clipCoords.x = pos.x*mvpmatrix[0] + pos.y*mvpmatrix[4] + (pos.z)*mvpmatrix[8] + mvpmatrix[12];
    	clipCoords.y = pos.x*mvpmatrix[1] + pos.y*mvpmatrix[5] + (pos.z)*mvpmatrix[9] + mvpmatrix[13];
    	clipCoords.z = pos.x*mvpmatrix[2] + pos.y*mvpmatrix[6] + (pos.z)*mvpmatrix[10] + mvpmatrix[14];
    	clipCoords.w = pos.x*mvpmatrix[3] + pos.y*mvpmatrix[7] + (pos.z)*mvpmatrix[11] + mvpmatrix[15];
    	if (clipCoords.w < 0.1f)
    		return false;
    	//perspective division, dividing by clip.W = NDC
    	Vec3D normalizedDeviceCoordinates;
    	normalizedDeviceCoordinates.x = clipCoords.x / clipCoords.w;
    	normalizedDeviceCoordinates.y = clipCoords.y / clipCoords.w;
    	normalizedDeviceCoordinates.z = clipCoords.z / clipCoords.w;
    	//viewport tranform to screenCooords
    	playerScreenCoords.x = (windowWidth / 2 * normalizedDeviceCoordinates.x) + (normalizedDeviceCoordinates.x + windowWidth / 2);
    	playerScreenCoords.y = -(windowHeight  / 2 * normalizedDeviceCoordinates.y) + (normalizedDeviceCoordinates.y + windowHeight / 2);
    	return true;
    Last edited by chetstar625; April 14th, 2016 at 17:15.


Posting Permissions

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