Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vect3 CCamera::WorldToScreen(vect3 coord)//i do this vect3 vWorldToScreen(vect3 coord)
- {
- float Y_fov = aCamera->Fov / aspect_ratio;//then lose the aspect_ratio cuz its in the class
- vect3 cam_to_obj(coord.x - aCamera->vWorld.x, coord.y - aCamera->vWorld.y, coord.z - aCamera->vWorld.z);
- float dist_to_obj = sqrt(cam_to_obj.x*cam_to_obj.x + cam_to_obj.y*cam_to_obj.y + cam_to_obj.z*cam_to_obj.z);
- D3DXVec3Normalize(&cam_to_obj, &cam_to_obj);
- // All angles are in radians, -PI<angle<PI, and no i dont know which could be equal to. but who cares - it's a float so it's impossible.
- float cam_yaw = atan2f(aCamera->vLookAt.y, aCamera->vLookAt.x);
- float obj_yaw = atan2f(cam_to_obj.y, cam_to_obj.x);
- // Relative(to cam) yaw ends up from -2 PI < yaw < 2 PI, but we want it from -PI<yaw<PI
- float relative_yaw = obj_yaw - cam_yaw;
- if(relative_yaw > D3DX_PI) // yaw>180 degrees. convert to negative, smaller.
- relative_yaw -= 2*D3DX_PI;
- if(relative_yaw < -D3DX_PI)
- relative_yaw += 2*D3DX_PI;
- // [/Difference]
- float obj_pitch = asin(cam_to_obj.z);
- float cam_pitch = asin(aCamera->vLookAt.z);
- float relative_pitch = cam_pitch - obj_pitch;
- float x_pos = -relative_yaw * 2 / aCamera->Fov; // radian angle measurement cancels here.
- float y_pos = relative_pitch * 2 / Y_fov; // and that's the (relative pitch) / (fov / 2)
- x_pos = (x_pos + 1) / 2; // Lastly, change from range (-1,1) to (0,1) Also, it CAN be outside of that range - if it's outside of the FOV.
- y_pos = (y_pos + 1) / 2;
- vect3 onscreen(x_pos, y_pos, dist_to_obj); //you have working camera struct? its here
- return onscreen;
- }
- way hack is used
- if(opt.hacks.test1)
- {
- for(unsigned short i = 0; i < StaticPlayerHeader->SlotsTaken; i++)
- {
- if(GetLocalPlayer(Local->PlayerIndex))
- {
- if(GetPlayerByIndex(i))
- {
- if(LocalPlayer->Team == StaticPlayer->Team)
- continue;
- //if(!Masterchief)
- // continue;
- D3DXVECTOR3 HeadPos, Head2DPos;
- HeadPos.x = Masterchief->Head[10] - aCamera->vWorld[0];
- HeadPos.y = Masterchief->Head[11] - aCamera->vWorld[1];
- HeadPos.z = Masterchief->Head[12] - aCamera->vWorld[2];
- if(Head2DPos = vWorldToScreen(HeadPos))
- {
- char strPlayerName[12];
- wcstombs(strPlayerName, StaticPlayer->PlayerName1, wcslen(StaticPlayer->PlayerName1)+1);
- Menu.font->DrawTextA(Head2DPos.x, Head2DPos.y, D3DCOLOR_ARGB(255,255,255,255), strPlayerName, DT_CENTER|DT_SHADOW);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement