2020-05-27 09:21:20 +02:00
|
|
|
#include "framework.h"
|
2019-12-30 21:10:01 +01:00
|
|
|
#include "sphere.h"
|
|
|
|
#include "draw.h"
|
2020-04-23 19:22:01 +02:00
|
|
|
#include "lara.h"
|
2020-05-27 09:21:20 +02:00
|
|
|
#include "level.h"
|
|
|
|
#include "setup.h"
|
2020-05-30 15:55:23 +02:00
|
|
|
#include "Renderer11.h"
|
|
|
|
#include "trmath.h"
|
2019-12-30 21:10:01 +01:00
|
|
|
|
2020-01-01 11:45:09 +01:00
|
|
|
int NumLaraSpheres;
|
|
|
|
bool GotLaraSpheres;
|
2020-04-27 06:33:42 +02:00
|
|
|
SPHERE LaraSpheres[MAX_SPHERES];
|
|
|
|
SPHERE CreatureSpheres[MAX_SPHERES];
|
2020-01-01 11:45:09 +01:00
|
|
|
|
2020-04-27 06:33:42 +02:00
|
|
|
int GetSpheres(ITEM_INFO* item, SPHERE* ptr, int worldSpace, Matrix local)
|
2019-12-30 21:10:01 +01:00
|
|
|
{
|
2020-04-26 10:55:33 +02:00
|
|
|
if (!item)
|
|
|
|
return 0;
|
|
|
|
|
2020-04-27 06:33:42 +02:00
|
|
|
BoundingSphere spheres[MAX_SPHERES];
|
|
|
|
short itemNumber = (item - Items);
|
2020-04-26 10:55:33 +02:00
|
|
|
|
|
|
|
int num = g_Renderer->GetSpheres(itemNumber, spheres, worldSpace, local);
|
|
|
|
|
2020-04-27 06:33:42 +02:00
|
|
|
for (int i = 0; i < MAX_SPHERES; i++)
|
2020-04-26 10:55:33 +02:00
|
|
|
{
|
|
|
|
ptr[i].x = spheres[i].Center.x;
|
|
|
|
ptr[i].y = spheres[i].Center.y;
|
|
|
|
ptr[i].z = spheres[i].Center.z;
|
|
|
|
ptr[i].r = spheres[i].Radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
2019-12-30 21:10:01 +01:00
|
|
|
}
|
|
|
|
|
2020-01-01 11:45:09 +01:00
|
|
|
int TestCollision(ITEM_INFO* item, ITEM_INFO* l)
|
|
|
|
{
|
|
|
|
int flags = 0;
|
|
|
|
|
2020-04-27 06:33:42 +02:00
|
|
|
int num1 = GetSpheres(item, CreatureSpheres, SPHERES_SPACE_WORLD, Matrix::Identity);
|
2020-01-01 11:45:09 +01:00
|
|
|
int num2 = 0;
|
|
|
|
|
|
|
|
if (l == LaraItem)
|
|
|
|
{
|
|
|
|
if (GotLaraSpheres)
|
|
|
|
{
|
|
|
|
num2 = NumLaraSpheres;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-27 06:33:42 +02:00
|
|
|
num2 = GetSpheres(l, LaraSpheres, SPHERES_SPACE_WORLD, Matrix::Identity);
|
2020-01-01 11:45:09 +01:00
|
|
|
NumLaraSpheres = num2;
|
|
|
|
if (l == LaraItem)
|
|
|
|
GotLaraSpheres = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GotLaraSpheres = false;
|
|
|
|
|
2020-04-27 06:33:42 +02:00
|
|
|
num2 = GetSpheres(l, LaraSpheres, SPHERES_SPACE_WORLD, Matrix::Identity);
|
2020-01-01 11:45:09 +01:00
|
|
|
NumLaraSpheres = num2;
|
|
|
|
if (l == LaraItem)
|
|
|
|
GotLaraSpheres = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
l->touchBits = 0;
|
|
|
|
|
|
|
|
if (num1 <= 0)
|
|
|
|
{
|
|
|
|
item->touchBits = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < num1; i++)
|
|
|
|
{
|
2020-04-27 06:33:42 +02:00
|
|
|
SPHERE* ptr1 = &CreatureSpheres[i];
|
2020-01-01 11:45:09 +01:00
|
|
|
|
2020-04-20 07:14:54 +02:00
|
|
|
int x1 = item->pos.xPos + ptr1->x;
|
|
|
|
int y1 = item->pos.yPos + ptr1->y;
|
|
|
|
int z1 = item->pos.zPos + ptr1->z;
|
2020-01-01 11:45:09 +01:00
|
|
|
int r1 = ptr1->r;
|
|
|
|
|
|
|
|
if (r1 > 0)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < num2; j++)
|
|
|
|
{
|
|
|
|
SPHERE* ptr2 = &LaraSpheres[j];
|
|
|
|
|
2020-04-20 07:14:54 +02:00
|
|
|
int x2 = item->pos.xPos + ptr2->x;
|
|
|
|
int y2 = item->pos.yPos + ptr2->y;
|
|
|
|
int z2 = item->pos.zPos + ptr2->z;
|
2020-01-01 11:45:09 +01:00
|
|
|
int r2 = ptr2->r;
|
|
|
|
|
|
|
|
if (r2 > 0)
|
|
|
|
{
|
|
|
|
int dx = x1 - x2;
|
|
|
|
int dy = y1 - y2;
|
|
|
|
int dz = z1 - z2;
|
|
|
|
int r = r1 + r2;
|
|
|
|
|
|
|
|
if (SQUARE(dx) + SQUARE(dy) + SQUARE(dz) < SQUARE(r))
|
|
|
|
{
|
|
|
|
l->touchBits |= (1 << j);
|
|
|
|
flags |= (1 << i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
item->touchBits = flags;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 07:14:54 +02:00
|
|
|
void GetMatrixFromTrAngle(Matrix* matrix, short* frameptr, int index)
|
2020-03-25 07:06:04 +01:00
|
|
|
{
|
2020-04-20 07:14:54 +02:00
|
|
|
short* ptr = &frameptr[0];
|
2020-03-25 07:06:04 +01:00
|
|
|
|
2020-04-20 07:14:54 +02:00
|
|
|
ptr += 9;
|
|
|
|
for (int i = 0; i < index; i++)
|
2020-03-25 07:06:04 +01:00
|
|
|
{
|
2020-04-20 07:14:54 +02:00
|
|
|
ptr += ((*ptr & 0xc000) == 0 ? 2 : 1);
|
2020-03-25 07:06:04 +01:00
|
|
|
}
|
|
|
|
|
2020-04-20 07:14:54 +02:00
|
|
|
int rot0 = *ptr++;
|
|
|
|
int frameMode = (rot0 & 0xc000);
|
2020-03-25 07:06:04 +01:00
|
|
|
|
2020-04-20 07:14:54 +02:00
|
|
|
int rot1;
|
|
|
|
int rotX;
|
|
|
|
int rotY;
|
|
|
|
int rotZ;
|
2020-03-25 07:06:04 +01:00
|
|
|
|
2020-04-20 07:14:54 +02:00
|
|
|
switch (frameMode)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
rot1 = *ptr++;
|
|
|
|
rotX = ((rot0 & 0x3ff0) >> 4);
|
|
|
|
rotY = (((rot1 & 0xfc00) >> 10) | ((rot0 & 0xf) << 6) & 0x3ff);
|
|
|
|
rotZ = ((rot1) & 0x3ff);
|
|
|
|
|
|
|
|
*matrix = Matrix::CreateFromYawPitchRoll(rotY * (360.0f / 1024.0f) * RADIAN,
|
|
|
|
rotX * (360.0f / 1024.0f) * RADIAN,
|
|
|
|
rotZ * (360.0f / 1024.0f) * RADIAN);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4000:
|
|
|
|
*matrix = Matrix::CreateRotationX((rot0 & 0xfff) * (360.0f / 4096.0f) * RADIAN);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x8000:
|
|
|
|
*matrix = Matrix::CreateRotationY((rot0 & 0xfff) * (360.0f / 4096.0f) * RADIAN);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xc000:
|
|
|
|
*matrix = Matrix::CreateRotationZ((rot0 & 0xfff) * (360.0f / 4096.0f) * RADIAN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-03-25 07:06:04 +01:00
|
|
|
|
2020-04-20 07:14:54 +02:00
|
|
|
void GetJointAbsPosition(ITEM_INFO* item, PHD_VECTOR* vec, int joint)
|
|
|
|
{
|
2020-04-26 10:55:33 +02:00
|
|
|
// Get the real item number
|
2020-04-27 06:33:42 +02:00
|
|
|
short itemNumber = item - Items;
|
2020-03-25 07:06:04 +01:00
|
|
|
|
2020-04-26 10:55:33 +02:00
|
|
|
// Use matrices done in the renderer and transform the input vector
|
2020-04-20 07:14:54 +02:00
|
|
|
Vector3 p = Vector3(vec->x, vec->y, vec->z);
|
|
|
|
g_Renderer->GetItemAbsBonePosition(itemNumber, &p, joint);
|
2020-03-25 07:06:04 +01:00
|
|
|
|
2020-04-26 10:55:33 +02:00
|
|
|
// Store the result
|
2020-04-20 07:14:54 +02:00
|
|
|
vec->x = p.x;
|
|
|
|
vec->y = p.y;
|
|
|
|
vec->z = p.z;
|
2020-03-25 07:06:04 +01:00
|
|
|
}
|
|
|
|
|