Held object fix

This commit is contained in:
Fazana
2021-09-28 21:52:00 +01:00
parent 79d7b7e4b9
commit cefd4b62ab
2 changed files with 38 additions and 58 deletions

View File

@@ -37,7 +37,7 @@ void vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) {
/// Add vector 'a' to 'dest'
void vec3f_add(Vec3f dest, Vec3f a) {
register f32 *temp = dest;
register f32 *temp = (f32 *)dest;
register s32 j;
register f32 sum, sum2;
for (j = 0; j < 3; j++) {
@@ -118,9 +118,6 @@ void vec3f_normalize(Vec3f dest) {
invsqrt = 1.0f / size;
vec3_mul_val(dest, invsqrt);
/*dest[0] *= invsqrt;
dest[1] *= invsqrt;
dest[2] *= invsqrt;*/
} else {
dest[0] = 0;
dest[1] = 1;
@@ -160,7 +157,7 @@ void mtxf_identity(register Mat4 mtx) {
*/
void mtxf_translate(Mat4 dest, Vec3f b) {
mtxf_identity(dest);
vec3f_copy(dest[3], b);
vec3_copy(dest[3], b);
}
void mtxf_rot_trans_mul(Vec3s rot, Vec3f trans, Mat4 dest, Mat4 src) {
@@ -212,7 +209,7 @@ void mtxf_rot_trans_mul(Vec3s rot, Vec3f trans, Mat4 dest, Mat4 src) {
f32 lookAtCalc(f32 sqrtsqrt) {
f32 calc = sqrtf(sqrtsqrt);
if (calc == 0)
calc = 0.00000000001;
calc = 0.001f;
return -1.0 / calc;
}
@@ -236,7 +233,6 @@ void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s32 roll) {
f32 xColX;
f32 yColX;
f32 zColX;
f32 calc;
dx = to[0] - from[0];
dz = to[2] - from[2];
@@ -375,7 +371,7 @@ void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f b, Vec3s c) {
void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s32 angle) {
register s32 i;
register f32 *temp, *temp2;
temp = dest;
temp = (f32 *)dest;
for (i = 0; i < 16; i++) {
*temp = 0;
temp++;
@@ -388,8 +384,8 @@ void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s32 angle) {
dest[2][3] = 0;
((u32 *) dest)[15] = 0x3F800000;
temp = dest;
temp2 = mtx;
temp = (f32 *)dest;
temp2 = (f32 *)mtx;
for (i = 0; i < 3; i++) {
temp[12] = temp2[0] * position[0] + temp2[4] * position[1] + temp2[8] * position[2] + temp2[12];
temp++;
@@ -448,7 +444,7 @@ void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s32 yaw) {
* 'radius' is the distance from each triangle vertex to the center
*/
void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s32 yaw, f32 radius) {
struct Surface *sp74;
struct Surface *floor;
Vec3f point0;
Vec3f point1;
Vec3f point2;
@@ -466,9 +462,9 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s32 yaw, f32 radius) {
point2[0] = pos[0] + radius * sins(yaw + 0xD555);
point2[2] = pos[2] + radius * coss(yaw + 0xD555);
point0[1] = find_floor(point0[0], pos[1] + 150, point0[2], &sp74);
point1[1] = find_floor(point1[0], pos[1] + 150, point1[2], &sp74);
point2[1] = find_floor(point2[0], pos[1] + 150, point2[2], &sp74);
point0[1] = find_floor(point0[0], pos[1] + 150, point0[2], &floor);
point1[1] = find_floor(point1[0], pos[1] + 150, point1[2], &floor);
point2[1] = find_floor(point2[0], pos[1] + 150, point2[2], &floor);
if (point0[1] - pos[1] < minY) {
point0[1] = pos[1];
@@ -482,29 +478,21 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s32 yaw, f32 radius) {
point2[1] = pos[1];
}
avgY = (point0[1] + point1[1] + point2[1]) * .3333333333333333333333333333333333333333333333f;
avgY = (point0[1] + point1[1] + point2[1]) / 3;
vec3f_set(forward, sins(yaw), 0, coss(yaw));
vec3_set(forward, sins(yaw), 0, coss(yaw));
find_vector_perpendicular_to_plane(yColumn, point0, point1, point2);
vec3f_normalize(yColumn);
vec3f_cross(xColumn, yColumn, forward);
vec3_cross(xColumn, yColumn, forward);
vec3f_normalize(xColumn);
vec3f_cross(zColumn, xColumn, yColumn);
vec3_cross(zColumn, xColumn, yColumn);
vec3f_normalize(zColumn);
vec3f_copy(mtx[0], xColumn);
vec3f_copy(mtx[1], yColumn);
vec3f_copy(mtx[2], zColumn);
mtx[0][0] = xColumn[0];
mtx[0][1] = xColumn[1];
mtx[0][2] = xColumn[2];
mtx[3][0] = pos[0];
mtx[1][0] = yColumn[0];
mtx[1][1] = yColumn[1];
mtx[1][2] = yColumn[2];
mtx[3][1] = (avgY < pos[1]) ? pos[1] : avgY;
mtx[2][0] = zColumn[0];
mtx[2][1] = zColumn[1];
mtx[2][2] = zColumn[2];
mtx[3][2] = pos[2];
mtx[0][3] = 0;
@@ -525,15 +513,15 @@ void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) {
register f32 entry0;
register f32 entry1;
register f32 entry2;
register f32 *temp = a;
register f32 *temp2 = dest;
register f32 *temp = (f32 *)a;
register f32 *temp2 = (f32 *)dest;
register f32 *temp3;
register s32 i;
for (i = 0; i < 16; i++) {
entry0 = temp[0];
entry1 = temp[1];
entry2 = temp[2];
temp3 = b;
temp3 = (f32 *)b;
for (; (i & 3) !=3; i++) {
*temp2 = entry0 * temp3[0] + entry1 * temp3[4] + entry2 * temp3[8];
temp2++;
@@ -543,7 +531,7 @@ void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) {
temp += 4;
temp2++;
}
vec3f_add(&dest[3][0], &b[3][0]);
vec3_add(&dest[3][0], &b[3][0]);
((u32 *) dest)[15] = 0x3F800000;
}
@@ -551,9 +539,10 @@ void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) {
* Set matrix 'dest' to 'mtx' scaled by vector s
*/
void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, register Vec3f s) {
register f32 *temp = dest;
register f32 *temp2 = mtx;
register f32 *temp = (f32 *)dest;
register f32 *temp2 = (f32 *)mtx;
register s32 i;
for (i = 0; i < 4; i++) {
temp[0] = temp2[0] * s[0];
temp[4] = temp2[4] * s[1];
@@ -573,7 +562,7 @@ void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
register f32 x = b[0];
register f32 y = b[1];
register f32 z = b[2];
register f32 *temp2 = mtx;
register f32 *temp2 = (f32 *)mtx;
register s32 i;
register s16 *c = b;
for (i = 0; i < 3; i++) {
@@ -636,7 +625,7 @@ void mtxf_to_mtx(void *dest, void *src) {
void mtxf_rotate_xy(Mtx *mtx, s32 angle) {
register s32 i = coss(angle) * 65536;
register s32 j = sins(angle) * 65536;
register f32 *temp = mtx;
register f32 *temp = (f32 *)mtx;
register s32 k;
for (k = 0; k < 16; k++) {
*temp = 0;
@@ -644,20 +633,8 @@ void mtxf_rotate_xy(Mtx *mtx, s32 angle) {
}
MATENTRY(0, i)
MATENTRY(1, j)
//((s32 *) mtx)[1] = 0;
MATENTRY(4, -j)
MATENTRY(5, i)
/*((s32 *) mtx)[3] = 0;
((s32 *) mtx)[4] = 0;
((s32 *) mtx)[5] = 0;
((s32 *) mtx)[6] = 0;
((s32 *) mtx)[7] = 0;
((s32 *) mtx)[9] = 0;
((s32 *) mtx)[11] = 0;
((s32 *) mtx)[12] = 0;
((s32 *) mtx)[13] = 0;
((s32 *) mtx)[14] = 0;
((s32 *) mtx)[15] = 0;*/
((s16 *) mtx)[10] = 1;
((s16 *) mtx)[15] = 1;
}
@@ -672,11 +649,11 @@ void mtxf_rotate_xy(Mtx *mtx, s32 angle) {
*/
void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, register Mat4 camMtx) {
register s32 i;
register f32 *temp = dest;
register f32 *temp2 = camMtx;
register f32 *temp = (f32 *)dest;
register f32 *temp2 = (f32 *)camMtx;
f32 y[3];
register f32 *x = y;
register f32 *temp3 = objMtx;
register f32 *temp3 = (f32 *)objMtx;
for (i = 0; i < 3; i++) {
*x = (temp3[12] - temp2[12]);
@@ -690,7 +667,6 @@ void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, register Mat4 camMtx) {
temp++;
temp2 += 4;
}
}