2019-12-02 14:49:19 +01:00
|
|
|
#include "camera.h"
|
2018-08-19 09:46:58 +02:00
|
|
|
#include <d3d9.h>
|
|
|
|
#include <d3dx9.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "draw.h"
|
2019-12-15 16:19:01 +01:00
|
|
|
|
2020-01-18 20:52:57 +01:00
|
|
|
#define LfAspectCorrection VAR_U_(0x0055DA30, float)
|
|
|
|
|
2019-12-15 16:19:01 +01:00
|
|
|
extern int KeyTriggerActive;
|
|
|
|
|
2020-01-18 20:52:57 +01:00
|
|
|
PHD_VECTOR CurrentCameraPosition;
|
|
|
|
SVECTOR CurrentCameraRotation;
|
|
|
|
|
2019-12-15 16:19:01 +01:00
|
|
|
void ActivateCamera()
|
|
|
|
{
|
|
|
|
KeyTriggerActive = 2;
|
|
|
|
}
|
|
|
|
|
2019-12-13 13:52:47 +01:00
|
|
|
void LookAt(int posX, int posY, int posZ, int targetX, int targetY, int targetZ, short roll)
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
2019-01-13 21:57:16 +01:00
|
|
|
Vector3 position = Vector3(posX, posY, posZ);
|
|
|
|
Vector3 target = Vector3(targetX, targetY, targetZ);
|
|
|
|
Vector3 up = Vector3(0.0f, -1.0f, 0.0f);
|
2019-12-11 07:40:47 +01:00
|
|
|
float fov = TR_ANGLE_TO_RAD(CurrentFOV / 1.333333f);
|
2019-05-31 21:45:13 +02:00
|
|
|
float r = TR_ANGLE_TO_RAD(roll);
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2019-12-25 08:44:01 +01:00
|
|
|
// This should not be needed but it seems to solve our issues
|
|
|
|
if (posX == targetX && posY == targetY && posZ == targetZ)
|
|
|
|
return;
|
|
|
|
|
2020-01-16 19:14:35 +01:00
|
|
|
short angles[2];
|
|
|
|
phd_GetVectorAngles(targetX - posX, targetY - posY, targetZ - posZ, angles);
|
|
|
|
|
|
|
|
PHD_3DPOS pos;
|
2020-01-18 20:52:57 +01:00
|
|
|
|
2020-01-16 19:14:35 +01:00
|
|
|
pos.xPos = posX;
|
|
|
|
pos.yPos = posY;
|
|
|
|
pos.zPos = posZ;
|
|
|
|
pos.xRot = angles[1];
|
|
|
|
pos.yRot = angles[0];
|
|
|
|
pos.zRot = roll;
|
|
|
|
|
2020-01-18 20:52:57 +01:00
|
|
|
CurrentCameraPosition.x = posX;
|
|
|
|
CurrentCameraPosition.y = posY;
|
|
|
|
CurrentCameraPosition.z = posZ;
|
|
|
|
|
|
|
|
CurrentCameraRotation.vx = mGetAngle(0, 0, sqrt(roll), posY - targetY) >> 4;
|
|
|
|
CurrentCameraRotation.vy = mGetAngle(posZ, posX, targetZ, targetX) >> 4;
|
|
|
|
CurrentCameraRotation.vz = 0;
|
2020-01-16 19:14:35 +01:00
|
|
|
|
|
|
|
phd_GenerateW2V(&pos);
|
|
|
|
|
2019-05-31 21:45:13 +02:00
|
|
|
g_Renderer->UpdateCameraMatrices(posX, posY, posZ, targetX, targetY, targetZ, r, fov);
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
|
2019-12-02 14:49:19 +01:00
|
|
|
void AlterFOV(int value)
|
2019-01-13 21:57:16 +01:00
|
|
|
{
|
2018-08-19 09:46:58 +02:00
|
|
|
CurrentFOV = value;
|
2018-11-06 23:01:00 +01:00
|
|
|
PhdPerspective = PhdWidth / 2 * COS(CurrentFOV / 2) / SIN(CurrentFOV / 2);
|
2020-01-18 20:52:57 +01:00
|
|
|
LfAspectCorrection = 1; // 1.3333334f / (float)(PhdWidth / PhdHeight);
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
|
2019-12-28 15:19:33 -03:00
|
|
|
int mgLOS(GAME_VECTOR* start, GAME_VECTOR* target, int push)
|
|
|
|
{
|
|
|
|
int x, y, z, dx, dy, dz, i, h, c;
|
|
|
|
short room, room2;
|
|
|
|
FLOOR_INFO* floor;
|
|
|
|
int flag, result;
|
|
|
|
|
|
|
|
x = start->x;
|
|
|
|
y = start->y;
|
|
|
|
z = start->z;
|
|
|
|
room = start->roomNumber;
|
|
|
|
dx = target->x - x >> 3;
|
|
|
|
dy = target->y - y >> 3;
|
|
|
|
dz = target->z - z >> 3;
|
|
|
|
flag = 0;
|
|
|
|
result = 0;
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
{
|
|
|
|
room2 = room;
|
|
|
|
floor = GetFloor(x, y, z, &room);
|
|
|
|
h = GetFloorHeight(floor, x, y, z);
|
|
|
|
c = GetCeiling(floor, x, y, z);
|
|
|
|
if (h != NO_HEIGHT && c != NO_HEIGHT && c < h)
|
|
|
|
{
|
|
|
|
if (y > h)
|
|
|
|
{
|
|
|
|
if (y - h >= push)
|
|
|
|
{
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
y = h;
|
|
|
|
}
|
|
|
|
if (y < c) {
|
|
|
|
if (c - y >= push)
|
|
|
|
{
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
y = c;
|
|
|
|
}
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
else if (result)
|
|
|
|
{
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
x += dx;
|
|
|
|
y += dy;
|
|
|
|
z += dz;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
x -= dx;
|
|
|
|
y -= dy;
|
|
|
|
z -= dz;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetFloor(x, y, z, &room2);
|
|
|
|
target->x = x;
|
|
|
|
target->y = y;
|
|
|
|
target->z = z;
|
|
|
|
target->roomNumber = room2;
|
|
|
|
|
|
|
|
return flag == 0;
|
|
|
|
}
|
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
void Inject_Camera()
|
|
|
|
{
|
2019-05-31 21:45:13 +02:00
|
|
|
INJECT(0x0048EDC0, AlterFOV);
|
|
|
|
INJECT(0x0048F760, LookAt);
|
2019-12-28 15:19:33 -03:00
|
|
|
INJECT(0x0040FA70, mgLOS);
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|