24.03.2010, 21:13
CODE EDITED - THIS IS CORRECT AND TESTED!
Код:
Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) { new Float:TGTDistance; // get distance from camera to target TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ)); new Float:tmpX, Float:tmpY, Float:tmpZ; tmpX = FrX * TGTDistance + CamX; tmpY = FrY * TGTDistance + CamY; tmpZ = FrZ * TGTDistance + CamZ; return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ)); }
Код:
// EXAMPLE USAGE: checkforcamera(PlayerID) { new Float:CameraPos[3]; new Float:CameraFront[3]; new Float:CheckObjectPos[3] = {-2661.2764,915.7676,79.6685}; // trash can near partyserver torenos GetPlayerCameraPos(PlayerID, CameraPos[0], CameraPos[1], CameraPos[2]); GetPlayerCameraFrontVector(PlayerID, CameraFront[0], CameraFront[1], CameraFront[2]); new Float:distc; distc = DistanceCameraTargetToLocation(CameraPos[0], CameraPos[1], CameraPos[2], CheckObjectPos[0], CheckObjectPos[1], CheckObjectPos[2], CameraFront[0], CameraFront[1], CameraFront[2]); new string[128]; if (distc < 2.0) { format(string,sizeof(string),"YOU SEE IT."); SendClientMessage(PlayerID, COLOR_RED, string); } return true; }