Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //globals:
- static float fWidth, fHeight, fHWidth, fHHeight;
- static float fFovMod;
- static Vector3 v3View, v3Right, v3Up, v3Forward;
- static public Memory.Matrix viewProj { get { return Memory.ReadMatrix(Mem.p, Memory.ReadPtr<IntPtr>(Mem.p, (long)Offsets.PlayerManagerPtr, new int[] { Offsets.PlayerManager.LocalPlayer, Offsets.Player.Camera, Offsets.Camera.Matrix })); } }
- //call this function only after a resolution has changed...
- public static void W2S_initonce(int dwWidth, int dwHeight/*, IDirect3DDevice9 *dev*/ )
- {
- fWidth = (float)dwWidth;
- fHeight = (float)dwHeight;
- fHWidth = fWidth / 2.0f;
- fHHeight = fHeight / 2.0f;
- }
- //call this function in your render function before drawing (once every frame)
- public static void W2S_update(Player plr)
- {
- //stuff that doesnt change while drawing doesnt need to be recalced EVERY FUCKING CALL TO W2S
- float fFov = plr.zoom; //get the current view fov from anywhere =)
- float fMod = fWidth / fHeight;
- v3Right = new Vector3(viewProj.m11, viewProj.m12, viewProj.m13); //viewmatrix->right
- v3Up = new Vector3(viewProj.m21, viewProj.m22, viewProj.m23); //viewmatrix->up
- v3Forward = new Vector3(viewProj.m31, viewProj.m32, viewProj.m33); //viewmatrix->fwd
- v3View = new Vector3(viewProj.m41, viewProj.m42, viewProj.m43); //viewmatrix->origin
- float fFovTmp = plr.zoom * (1.25f + ((1.1f - plr.zoom) / 10.0f));
- fFovMod = (float)(fHWidth / Math.Tan(fFovTmp / 2.0f));
- }
- //the actual W2S
- public static bool W2S_project(ref Vector3 coord)
- {
- Vector3 diff = Vector3.Zero;
- Vector3.Subtract(ref v3View, ref coord, out diff);
- float z = Vector3.Dot(diff, v3Forward);
- if (z <= 0.1f)
- {
- return false;
- }
- coord.X = fHWidth + Vector3.Dot(diff, v3Right) / z * fFovMod;
- coord.Y = fHHeight - Vector3.Dot(diff, v3Up) / z * fFovMod;
- coord.Z = z;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement