Subversion Repositories Games.Carmageddon

Rev

Rev 1 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 18
Line 1... Line 1...
1
#include "finteray.h"
1
#include "finteray.h"
2
#include "brender/brender.h"
2
#include "brender.h"
3
#include "brucetrk.h"
3
#include "brucetrk.h"
4
#include "car.h"
4
#include "car.h"
-
 
5
#include "formats.h"
5
#include "globvars.h"
6
#include "globvars.h"
6
#include "harness/trace.h"
7
#include "harness/trace.h"
7
#include "raycast.h"
8
#include "raycast.h"
8
#include "world.h"
9
#include "world.h"
9
#include <math.h>
10
#include <math.h>
Line 180... Line 181...
180
}
181
}
181
 
182
 
182
// IDA: int __usercall DRModelPick2D@<EAX>(br_model *model@<EAX>, br_material *material@<EDX>, br_vector3 *ray_pos@<EBX>, br_vector3 *ray_dir@<ECX>, br_scalar t_near, br_scalar t_far, dr_modelpick2d_cbfn *callback, void *arg)
183
// IDA: int __usercall DRModelPick2D@<EAX>(br_model *model@<EAX>, br_material *material@<EDX>, br_vector3 *ray_pos@<EBX>, br_vector3 *ray_dir@<ECX>, br_scalar t_near, br_scalar t_far, dr_modelpick2d_cbfn *callback, void *arg)
183
//  Suffix added to avoid duplicate symbol
184
//  Suffix added to avoid duplicate symbol
184
int DRModelPick2D__finteray(br_model* model, br_material* material, br_vector3* ray_pos, br_vector3* ray_dir, br_scalar t_near, br_scalar t_far, dr_modelpick2d_cbfn* callback, void* arg) {
185
int DRModelPick2D__finteray(br_model* model, br_material* material, br_vector3* ray_pos, br_vector3* ray_dir, br_scalar t_near, br_scalar t_far, dr_modelpick2d_cbfn* callback, void* arg) {
185
    DR_FACE* fp;
186
    // DR_FACE* fp;
186
    int f;
187
    int f;
187
    int axis_m;
188
    int axis_m;
188
    int axis_0;
189
    int axis_0;
189
    int axis_1;
190
    int axis_1;
190
    br_scalar t;
191
    br_scalar t;
191
    //br_scalar n; // Pierre-Marie Baty -- unused variable
192
    br_scalar n;
192
    br_scalar d;
193
    br_scalar d;
193
    br_vector3 p;
194
    br_vector3 p;
194
    float u0;
195
    float u0;
195
    float u1;
196
    float u1;
196
    float u2;
197
    float u2;
Line 209... Line 210...
209
    int v;
210
    int v;
210
    int e;
211
    int e;
211
    int r;
212
    int r;
212
    br_material* this_material;
213
    br_material* this_material;
213
    br_scalar numerator;
214
    br_scalar numerator;
214
    //float f_numerator; // Pierre-Marie Baty -- unused variable
215
    float f_numerator;
215
    int group;
216
    int group;
216
    LOG_TRACE("(%p, %p, %p, %p, %f, %f, %p, %p)", model, material, ray_pos, ray_dir, t_near, t_far, callback, arg);
217
    LOG_TRACE("(%p, %p, %p, %p, %f, %f, %p, %p)", model, material, ray_pos, ray_dir, t_near, t_far, callback, arg);
-
 
218
 
-
 
219
    struct v11group* grp_ptr;
-
 
220
    br_vector4* eqn;
217
 
221
 
218
    t_near -= 0.00001f;
222
    t_near -= 0.00001f;
219
    t_far += 0.00001f;
223
    t_far += 0.00001f;
220
    for (group = 0; group < V11MODEL(model)->ngroups; group++) {
224
    for (group = 0; group < V11MODEL(model)->ngroups; group++) {
-
 
225
        grp_ptr = &V11MODEL(model)->groups[group];
221
        for (f = 0; f < V11MODEL(model)->groups[group].nfaces; f++) {
226
        for (f = 0; f < V11MODEL(model)->groups[group].nfaces; f++) {
222
            fp = &V11MODEL(model)->groups[group].faces[f];
227
            eqn = &V11MODEL(model)->groups[group].eqn[f];
223
            if (V11MODEL(model)->groups[group].face_colours_material) {
228
            if (V11MODEL(model)->groups[group].user) {
224
                this_material = V11MODEL(model)->groups[group].face_colours_material;
229
                this_material = V11MODEL(model)->groups[group].user;
225
            } else {
230
            } else {
226
                this_material = material;
231
                this_material = material;
227
            }
232
            }
228
            d = fp->eqn.v[1] * ray_dir->v[1] + fp->eqn.v[2] * ray_dir->v[2] + fp->eqn.v[0] * ray_dir->v[0];
233
            d = BrVector3Dot(eqn, ray_dir);
229
            if (fabs(d) >= 0.00000023841858 && (!this_material || !this_material->identifier || *this_material->identifier != '!' || !gPling_materials)
234
            if (fabs(d) >= 0.00000023841858 && (!this_material || !this_material->identifier || *this_material->identifier != '!' || !gPling_materials)
230
                && (!this_material || (this_material->flags & 0x1800) != 0 || d <= 0.0)) {
235
                && (!this_material || (this_material->flags & 0x1800) != 0 || d <= 0.0)) {
231
                numerator = fp->eqn.v[1] * ray_pos->v[1]
236
                numerator = eqn->v[1] * ray_pos->v[1]
232
                    + fp->eqn.v[2] * ray_pos->v[2]
237
                    + eqn->v[2] * ray_pos->v[2]
233
                    + fp->eqn.v[0] * ray_pos->v[0]
238
                    + eqn->v[0] * ray_pos->v[0]
234
                    - fp->eqn.v[3];
239
                    - eqn->v[3];
235
                if (!BadDiv__finteray(numerator, d)) {
240
                if (!BadDiv__finteray(numerator, d)) {
236
                    t = -(numerator / d);
241
                    t = -(numerator / d);
237
                    if (t >= t_near && t <= t_far) {
242
                    if (t >= t_near && t <= t_far) {
238
                        BrVector3Scale(&p, ray_dir, t);
243
                        BrVector3Scale(&p, ray_dir, t);
239
                        BrVector3Accumulate(&p, ray_pos);
244
                        BrVector3Accumulate(&p, ray_pos);
240
                        axis_m = fabsf(fp->eqn.v[0]) < fabsf(fp->eqn.v[1]);
245
                        axis_m = fabsf(eqn->v[0]) < fabsf(eqn->v[1]);
241
                        if (fabsf(fp->eqn.v[2]) > fabsf(fp->eqn.v[axis_m])) {
246
                        if (fabsf(eqn->v[2]) > fabsf(eqn->v[axis_m])) {
242
                            axis_m = 2;
247
                            axis_m = 2;
243
                        }
248
                        }
244
                        if (axis_m) {
249
                        if (axis_m) {
245
                            axis_0 = 0;
250
                            axis_0 = 0;
246
                            if (axis_m == 1) {
251
                            if (axis_m == 1) {
Line 251... Line 256...
251
                        } else {
256
                        } else {
252
                            axis_0 = 1;
257
                            axis_0 = 1;
253
                            axis_1 = 2;
258
                            axis_1 = 2;
254
                        }
259
                        }
255
 
260
 
256
                        v0 = V11MODEL(model)->groups[group].vertices[fp->vertices[0]].p.v[axis_0];
261
                        v0 = grp_ptr->position[grp_ptr->vertex_numbers[f].v[0]].v[axis_0];
257
                        u0 = V11MODEL(model)->groups[group].vertices[fp->vertices[0]].p.v[axis_1];
262
                        u0 = grp_ptr->position[grp_ptr->vertex_numbers[f].v[0]].v[axis_1];
258
                        v1 = V11MODEL(model)->groups[group].vertices[fp->vertices[1]].p.v[axis_0] - v0;
263
                        v1 = grp_ptr->position[grp_ptr->vertex_numbers[f].v[1]].v[axis_0] - v0;
259
                        u1 = V11MODEL(model)->groups[group].vertices[fp->vertices[1]].p.v[axis_1] - u0;
264
                        u1 = grp_ptr->position[grp_ptr->vertex_numbers[f].v[1]].v[axis_1] - u0;
260
                        v2 = V11MODEL(model)->groups[group].vertices[fp->vertices[2]].p.v[axis_0] - v0;
265
                        v2 = grp_ptr->position[grp_ptr->vertex_numbers[f].v[2]].v[axis_0] - v0;
261
                        u2 = V11MODEL(model)->groups[group].vertices[fp->vertices[2]].p.v[axis_1] - u0;
266
                        u2 = grp_ptr->position[grp_ptr->vertex_numbers[f].v[2]].v[axis_1] - u0;
262
 
267
 
263
                        v0i1 = p.v[axis_0] - v0;
268
                        v0i1 = p.v[axis_0] - v0;
264
                        v0i2 = p.v[axis_1] - u0;
269
                        v0i2 = p.v[axis_1] - u0;
265
                        if (fabs(v1) > 0.0000002384185791015625) {
270
                        if (fabs(v1) > 0.0000002384185791015625) {
266
                            f_n = u2 * v1 - u1 * v2;
271
                            f_n = u2 * v1 - u1 * v2;
Line 292... Line 297...
292
                        }
297
                        }
293
 
298
 
294
                        if (alpha >= 0.0 && beta + alpha <= 1.0) {
299
                        if (alpha >= 0.0 && beta + alpha <= 1.0) {
295
                            s_alpha = alpha;
300
                            s_alpha = alpha;
296
                            s_beta = beta;
301
                            s_beta = beta;
297
                            map.v[0] = V11MODEL(model)->groups[group].vertices[fp->vertices[1]].map.v[0] * s_alpha;
-
 
298
                            map.v[1] = V11MODEL(model)->groups[group].vertices[fp->vertices[1]].map.v[1] * s_alpha;
302
                            BrVector2Scale(&map, &grp_ptr->map[grp_ptr->vertex_numbers[f].v[1]], s_alpha);
299
                            DRVector2AccumulateScale__finteray(
303
                            DRVector2AccumulateScale__finteray(
300
                                &map,
304
                                &map,
301
                                &V11MODEL(model)->groups[group].vertices[fp->vertices[2]].map,
305
                                &grp_ptr->map[grp_ptr->vertex_numbers[f].v[2]],
302
                                s_beta);
306
                                s_beta);
303
                            DRVector2AccumulateScale__finteray(
307
                            DRVector2AccumulateScale__finteray(
304
                                &map,
308
                                &map,
305
                                &V11MODEL(model)->groups[group].vertices[fp->vertices[0]].map,
309
                                &grp_ptr->map[grp_ptr->vertex_numbers[f].v[0]],
306
                                1.0 - (s_alpha + s_beta));
310
                                1.0 - (s_alpha + s_beta));
307
                            v = 0;
311
                            v = 0;
308
                            e = 1;
312
                            e = 1;
309
                            if (s_alpha <= s_beta) {
313
                            if (s_alpha <= s_beta) {
310
                                if (0.5 - s_beta / 2.0 > s_alpha) {
314
                                if (0.5 - s_beta / 2.0 > s_alpha) {
Line 363... Line 367...
363
 
367
 
364
// IDA: void __usercall FindFace(br_vector3 *pPosition@<EAX>, br_vector3 *pDir@<EDX>, br_vector3 *nor@<EBX>, br_scalar *t@<ECX>, br_material **material)
368
// IDA: void __usercall FindFace(br_vector3 *pPosition@<EAX>, br_vector3 *pDir@<EDX>, br_vector3 *nor@<EBX>, br_scalar *t@<ECX>, br_material **material)
365
void FindFace(br_vector3* pPosition, br_vector3* pDir, br_vector3* nor, br_scalar* t, br_material** material) {
369
void FindFace(br_vector3* pPosition, br_vector3* pDir, br_vector3* nor, br_scalar* t, br_material** material) {
366
    int group;
370
    int group;
367
    LOG_TRACE("(%p, %p, %p, %p, %p)", pPosition, pDir, nor, t, material);
371
    LOG_TRACE("(%p, %p, %p, %p, %p)", pPosition, pDir, nor, t, material);
-
 
372
 
-
 
373
    br_vector4* eqn;
368
 
374
 
369
    gNearest_T = 100.0f;
375
    gNearest_T = 100.0f;
370
    DRSceneRayPick2D(gTrack_actor, pPosition, pDir, FindHighestCallBack__finteray);
376
    DRSceneRayPick2D(gTrack_actor, pPosition, pDir, FindHighestCallBack__finteray);
371
    *t = gNearest_T;
377
    *t = gNearest_T;
372
    if (*t < 100.0f) {
378
    if (*t < 100.0f) {
373
        group = gNearest_face_group;
379
        group = gNearest_face_group;
374
        nor->v[0] = V11MODEL(gNearest_model)->groups[group].faces[gNearest_face].eqn.v[0];
380
        eqn = &V11MODEL(gNearest_model)->groups[group].eqn[gNearest_face];
-
 
381
        nor->v[0] = eqn->v[0];
375
        nor->v[1] = V11MODEL(gNearest_model)->groups[group].faces[gNearest_face].eqn.v[1];
382
        nor->v[1] = eqn->v[1];
376
        nor->v[2] = V11MODEL(gNearest_model)->groups[group].faces[gNearest_face].eqn.v[2];
383
        nor->v[2] = eqn->v[2];
377
        *material = V11MODEL(gNearest_model)->groups[group].face_colours_material;
384
        *material = V11MODEL(gNearest_model)->groups[group].user;
378
    }
385
    }
379
}
386
}
380
 
387
 
381
// IDA: void __cdecl EnablePlingMaterials()
388
// IDA: void __cdecl EnablePlingMaterials()
382
void EnablePlingMaterials(void) {
389
void EnablePlingMaterials(void) {
Line 420... Line 427...
420
 
427
 
421
    this_material = pFace->material;
428
    this_material = pFace->material;
422
    *rt = 100.0;
429
    *rt = 100.0;
423
 
430
 
424
    d = pFace->normal.v[1] * ray_dir->v[1] + ray_dir->v[2] * pFace->normal.v[2] + ray_dir->v[0] * pFace->normal.v[0];
431
    d = pFace->normal.v[1] * ray_dir->v[1] + ray_dir->v[2] * pFace->normal.v[2] + ray_dir->v[0] * pFace->normal.v[0];
425
    if ((this_material == NULL || (this_material->flags & (BR_MATF_TWO_SIDED | BR_MATF_ALWAYS_VISIBLE )) != 0 || d <= 0.0)
432
    if ((this_material == NULL || (this_material->flags & (BR_MATF_TWO_SIDED | BR_MATF_ALWAYS_VISIBLE)) != 0 || d <= 0.0)
426
        && (!this_material || !this_material->identifier || *this_material->identifier != '!' || !gPling_materials)
433
        && (!this_material || !this_material->identifier || *this_material->identifier != '!' || !gPling_materials)
427
        && fabs(d) >= 0.00000023841858) {
434
        && fabs(d) >= 0.00000023841858) {
428
        BrVector3Sub(&p, ray_pos, &pFace->v[0]);
435
        BrVector3Sub(&p, ray_pos, &pFace->v[0]);
429
        numerator = BrVector3Dot(&pFace->normal, &p);
436
        numerator = BrVector3Dot(&pFace->normal, &p);
430
        if (!BadDiv__finteray(numerator, d)) {
437
        if (!BadDiv__finteray(numerator, d)) {
Line 706... Line 713...
706
    return j;
713
    return j;
707
}
714
}
708
 
715
 
709
// IDA: int __usercall FindFacesInBox2@<EAX>(tBounds *bnds@<EAX>, tFace_ref *face_list@<EDX>, int max_face@<EBX>)
716
// IDA: int __usercall FindFacesInBox2@<EAX>(tBounds *bnds@<EAX>, tFace_ref *face_list@<EDX>, int max_face@<EBX>)
710
int FindFacesInBox2(tBounds* bnds, tFace_ref* face_list, int max_face) {
717
int FindFacesInBox2(tBounds* bnds, tFace_ref* face_list, int max_face) {
711
    //br_vector3 a; // Pierre-Marie Baty -- unused variable
718
    br_vector3 a;
712
    //br_vector3 b; // Pierre-Marie Baty -- unused variable
719
    br_vector3 b;
713
    //br_vector3 c[3]; // Pierre-Marie Baty -- unused variable
720
    br_vector3 c[3];
714
    //int i; // Pierre-Marie Baty -- unused variable
721
    int i;
715
    //int j; // Pierre-Marie Baty -- unused variable
722
    int j;
716
    LOG_TRACE("(%p, %p, %d)", bnds, face_list, max_face);
723
    LOG_TRACE("(%p, %p, %d)", bnds, face_list, max_face);
-
 
724
 
-
 
725
    a.v[0] = (bnds->original_bounds.min.v[0] + bnds->original_bounds.max.v[0]) * .5f;
-
 
726
    a.v[1] = (bnds->original_bounds.min.v[1] + bnds->original_bounds.max.v[1]) * .5f;
-
 
727
    a.v[2] = (bnds->original_bounds.min.v[2] + bnds->original_bounds.max.v[2]) * .5f;
-
 
728
    BrMatrix34ApplyP(&bnds->box_centre, &a, bnds->mat);
-
 
729
    BrVector3Sub(&b, &bnds->original_bounds.max, &bnds->original_bounds.min);
-
 
730
    bnds->radius = BrVector3Length(&b) / 2.f;
-
 
731
    BrMatrix34ApplyP(&bnds->real_bounds.min, &bnds->original_bounds.min, bnds->mat);
-
 
732
    BrVector3Copy(&bnds->real_bounds.max, &bnds->real_bounds.min);
717
    NOT_IMPLEMENTED();
733
    for (i = 0; i < 3; i++) {
-
 
734
        BrVector3Scale(&c[i], (br_vector3*)bnds->mat->m[i], b.v[i]);
-
 
735
    }
-
 
736
    for (i = 0; i < 3; i++) {
-
 
737
      bnds->real_bounds.min.v[i] += MIN(0.f, c[0].v[i]) + MIN(0.f, c[1].v[i]) + MIN(0.f, c[2].v[i]);
-
 
738
      bnds->real_bounds.max.v[i] += MAX(0.f, c[0].v[i]) + MAX(0.f, c[1].v[i]) + MAX(0.f, c[2].v[i]);
-
 
739
  }
-
 
740
  return max_face - ActorBoxPick(bnds, gTrack_actor, model_unk1, material_unk1, face_list, max_face, NULL);
718
}
741
}
719
 
742
 
720
// IDA: int __usercall ActorBoxPick@<EAX>(tBounds *bnds@<EAX>, br_actor *ap@<EDX>, br_model *model@<EBX>, br_material *material@<ECX>, tFace_ref *face_list, int max_face, br_matrix34 *pMat)
743
// IDA: int __usercall ActorBoxPick@<EAX>(tBounds *bnds@<EAX>, br_actor *ap@<EDX>, br_model *model@<EBX>, br_material *material@<ECX>, tFace_ref *face_list, int max_face, br_matrix34 *pMat)
721
int ActorBoxPick(tBounds* bnds, br_actor* ap, br_model* model, br_material* material, tFace_ref* face_list, int max_face, br_matrix34* pMat) {
744
int ActorBoxPick(tBounds* bnds, br_actor* ap, br_model* model, br_material* material, tFace_ref* face_list, int max_face, br_matrix34* pMat) {
722
    br_model* this_model;
745
    br_model* this_model;
Line 815... Line 838...
815
int ModelPickBox(br_actor* actor, tBounds* bnds, br_model* model, br_material* model_material, tFace_ref* face_list, int max_face, br_matrix34* pMat) {
838
int ModelPickBox(br_actor* actor, tBounds* bnds, br_model* model, br_material* model_material, tFace_ref* face_list, int max_face, br_matrix34* pMat) {
816
    int f;
839
    int f;
817
    int i;
840
    int i;
818
    int n;
841
    int n;
819
    int group;
842
    int group;
820
    DR_FACE* fp;
843
    // DR_FACE* fp;
821
    int v1;
844
    int v1;
822
    int v2;
845
    int v2;
823
    int v3;
846
    int v3;
824
    br_vector3 polygon[12];
847
    br_vector3 polygon[12];
825
    br_vector3 a;
848
    br_vector3 a;
826
    br_vector3 tv;
849
    br_vector3 tv;
827
    br_scalar t;
850
    br_scalar t;
828
    v11model* prepared;
851
    struct v11model* prepared;
829
    LOG_TRACE("(%p, %p, %p, %p, %p, %d, %p)", actor, bnds, model, model_material, face_list, max_face, pMat);
852
    LOG_TRACE("(%p, %p, %p, %p, %p, %d, %p)", actor, bnds, model, model_material, face_list, max_face, pMat);
-
 
853
 
-
 
854
    struct v11group* grp_ptr;
830
 
855
 
831
    prepared = model->prepared;
856
    prepared = model->prepared;
832
    if (max_face <= 0) {
857
    if (max_face <= 0) {
833
        return 0;
858
        return 0;
834
    }
859
    }
835
    for (group = 0; prepared->ngroups > group; group++) {
860
    for (group = 0; prepared->ngroups > group; group++) {
-
 
861
        grp_ptr = &prepared->groups[group];
836
        for (f = 0; f < prepared->groups[group].nfaces; f++) {
862
        for (f = 0; f < prepared->groups[group].nfaces; f++) {
837
            fp = &prepared->groups[group].faces[f];
863
            // fp = &prepared->groups[group].faces[f];
838
            v1 = fp->vertices[0];
864
            v1 = grp_ptr->vertex_numbers[f].v[0]; // fp->vertices[0];
839
            BrVector3Sub(&a, &prepared->groups[group].vertices[v1].p, &bnds->box_centre);
865
            // BrVector3Sub(&a, &prepared->groups[group].vertices[v1].p, &bnds->box_centre);
-
 
866
            BrVector3Sub(&a, &grp_ptr->position[v1], &bnds->box_centre);
840
            t = BrVector3Dot((br_vector3*)&fp->eqn, &a);
867
            // t = BrVector3Dot((br_vector3*)&fp->eqn, &a);
-
 
868
            t = BrVector3Dot((br_vector3*)&grp_ptr->eqn[f], &a);
841
            if (fabsf(t) > bnds->radius) {
869
            if (fabsf(t) > bnds->radius) {
842
                continue;
870
                continue;
843
            }
871
            }
844
            v2 = fp->vertices[1];
872
            // v2 = fp->vertices[1];
845
            v3 = fp->vertices[2];
873
            // v3 = fp->vertices[2];
-
 
874
            v2 = grp_ptr->vertex_numbers[f].v[1];
-
 
875
            v3 = grp_ptr->vertex_numbers[f].v[2];
846
 
876
 
847
            t = bnds->real_bounds.min.v[0];
877
            t = bnds->real_bounds.min.v[0];
848
            if (t > prepared->groups[group].vertices[v1].p.v[0]
878
            if (t > grp_ptr->position[v1].v[0]
849
                && t > prepared->groups[group].vertices[v2].p.v[0]
879
                && t > grp_ptr->position[v2].v[0]
850
                && t > prepared->groups[group].vertices[v3].p.v[0]) {
880
                && t > grp_ptr->position[v3].v[0]) {
851
                continue;
881
                continue;
852
            }
882
            }
853
            t = bnds->real_bounds.max.v[0];
883
            t = bnds->real_bounds.max.v[0];
854
            if (t < prepared->groups[group].vertices[v1].p.v[0]
884
            if (t < grp_ptr->position[v1].v[0]
855
                && t < prepared->groups[group].vertices[v2].p.v[0]
885
                && t < grp_ptr->position[v2].v[0]
856
                && t < prepared->groups[group].vertices[v3].p.v[0]) {
886
                && t < grp_ptr->position[v3].v[0]) {
857
                continue;
887
                continue;
858
            }
888
            }
859
            t = bnds->real_bounds.min.v[1];
889
            t = bnds->real_bounds.min.v[1];
860
            if (t > prepared->groups[group].vertices[v1].p.v[1]
890
            if (t > grp_ptr->position[v1].v[1]
861
                && t > prepared->groups[group].vertices[v2].p.v[1]
891
                && t > grp_ptr->position[v2].v[1]
862
                && t > prepared->groups[group].vertices[v3].p.v[1]) {
892
                && t > grp_ptr->position[v3].v[1]) {
863
                continue;
893
                continue;
864
            }
894
            }
865
            t = bnds->real_bounds.max.v[1];
895
            t = bnds->real_bounds.max.v[1];
866
            if (t < prepared->groups[group].vertices[v1].p.v[1]
896
            if (t < grp_ptr->position[v1].v[1]
867
                && t < prepared->groups[group].vertices[v2].p.v[1]
897
                && t < grp_ptr->position[v2].v[1]
868
                && t < prepared->groups[group].vertices[v3].p.v[1]) {
898
                && t < grp_ptr->position[v3].v[1]) {
869
                continue;
899
                continue;
870
            }
900
            }
871
            t = bnds->real_bounds.min.v[2];
901
            t = bnds->real_bounds.min.v[2];
872
            if (t > prepared->groups[group].vertices[v1].p.v[2]
902
            if (t > grp_ptr->position[v1].v[2]
873
                && t > prepared->groups[group].vertices[v2].p.v[2]
903
                && t > grp_ptr->position[v2].v[2]
874
                && t > prepared->groups[group].vertices[v3].p.v[2]) {
904
                && t > grp_ptr->position[v3].v[2]) {
875
                continue;
905
                continue;
876
            }
906
            }
877
            t = bnds->real_bounds.max.v[2];
907
            t = bnds->real_bounds.max.v[2];
878
            if (t < prepared->groups[group].vertices[v1].p.v[2]
908
            if (t < grp_ptr->position[v1].v[2]
879
                && t < prepared->groups[group].vertices[v2].p.v[2]
909
                && t < grp_ptr->position[v2].v[2]
880
                && t < prepared->groups[group].vertices[v3].p.v[2]) {
910
                && t < grp_ptr->position[v3].v[2]) {
881
                continue;
911
                continue;
882
            }
912
            }
883
            BrVector3Sub(&polygon[1], &prepared->groups[group].vertices[v1].p, (br_vector3*)bnds->mat->m[3]);
913
            BrVector3Sub(&polygon[1], &grp_ptr->position[v1], (br_vector3*)bnds->mat->m[3]);
884
            BrVector3Sub(&polygon[2], &prepared->groups[group].vertices[v2].p, (br_vector3*)bnds->mat->m[3]);
914
            BrVector3Sub(&polygon[2], &grp_ptr->position[v2], (br_vector3*)bnds->mat->m[3]);
885
            BrVector3Sub(&polygon[3], &prepared->groups[group].vertices[v3].p, (br_vector3*)bnds->mat->m[3]);
915
            BrVector3Sub(&polygon[3], &grp_ptr->position[v3], (br_vector3*)bnds->mat->m[3]);
886
            BrMatrix34TApplyV(&polygon[0], &polygon[1], bnds->mat);
916
            BrMatrix34TApplyV(&polygon[0], &polygon[1], bnds->mat);
887
            BrMatrix34TApplyV(&polygon[1], &polygon[2], bnds->mat);
917
            BrMatrix34TApplyV(&polygon[1], &polygon[2], bnds->mat);
888
            BrMatrix34TApplyV(&polygon[2], &polygon[3], bnds->mat);
918
            BrMatrix34TApplyV(&polygon[2], &polygon[3], bnds->mat);
889
            n = 3;
919
            n = 3;
890
            for (i = 0; i < 3; i++) {
920
            for (i = 0; i < 3; i++) {
Line 897... Line 927...
897
                    break;
927
                    break;
898
                }
928
                }
899
            }
929
            }
900
            if (n >= 3) {
930
            if (n >= 3) {
901
                if (pMat != NULL) {
931
                if (pMat != NULL) {
902
                    BrMatrix34ApplyP(&face_list->v[0], &prepared->groups[group].vertices[v1].p, pMat);
932
                    BrMatrix34ApplyP(&face_list->v[0], &grp_ptr->position[v1], pMat);
903
                    BrMatrix34ApplyP(&face_list->v[1], &prepared->groups[group].vertices[v2].p, pMat);
933
                    BrMatrix34ApplyP(&face_list->v[1], &grp_ptr->position[v2], pMat);
904
                    BrMatrix34ApplyP(&face_list->v[2], &prepared->groups[group].vertices[v3].p, pMat);
934
                    BrMatrix34ApplyP(&face_list->v[2], &grp_ptr->position[v3], pMat);
905
                    BrVector3Copy(&tv, (br_vector3*)&fp->eqn);
935
                    BrVector3Copy(&tv, (br_vector3*)&grp_ptr->eqn[f]);
906
                    BrMatrix34ApplyV(&face_list->normal, &tv, pMat);
936
                    BrMatrix34ApplyV(&face_list->normal, &tv, pMat);
907
                } else {
937
                } else {
908
                    BrVector3Copy(&face_list->v[0], &prepared->groups[group].vertices[v1].p);
938
                    BrVector3Copy(&face_list->v[0], &grp_ptr->position[v1]);
909
                    BrVector3Copy(&face_list->v[1], &prepared->groups[group].vertices[v2].p);
939
                    BrVector3Copy(&face_list->v[1], &grp_ptr->position[v2]);
910
                    BrVector3Copy(&face_list->v[2], &prepared->groups[group].vertices[v3].p);
940
                    BrVector3Copy(&face_list->v[2], &grp_ptr->position[v3]);
911
                    BrVector3Copy(&face_list->normal, (br_vector3*)&fp->eqn);
941
                    BrVector3Copy(&face_list->normal, (br_vector3*)&grp_ptr->eqn[f]);
912
                }
942
                }
913
                if (prepared->groups[group].face_colours_material != NULL) {
943
                if (prepared->groups[group].user != NULL) {
914
                    face_list->material = prepared->groups[group].face_colours_material;
944
                    face_list->material = prepared->groups[group].user;
915
                } else {
945
                } else {
916
                    face_list->material = model_material;
946
                    face_list->material = model_material;
917
                }
947
                }
918
                face_list->flags = 0;
948
                face_list->flags = 0;
919
                if (face_list->material != NULL && (face_list->material->flags & (BR_MATF_TWO_SIDED | BR_MATF_ALWAYS_VISIBLE)) == 0) {
949
                if (face_list->material != NULL && (face_list->material->flags & (BR_MATF_TWO_SIDED | BR_MATF_ALWAYS_VISIBLE)) == 0) {
920
                    face_list->flags |= (v1 < v2) | (v2 < v3) << 1 | (v3 < v1) << 2;
950
                    face_list->flags |= (v1 < v2) | (v2 < v3) << 1 | (v3 < v1) << 2;
921
                }
951
                }
922
                if (pMat != NULL) {
952
                if (pMat != NULL) {
923
                    face_list->d = BrVector3LengthSquared(&face_list->v[0]);
953
                    face_list->d = BrVector3LengthSquared(&face_list->v[0]);
924
                } else {
954
                } else {
925
                    face_list->d = fp->eqn.v[3];
955
                    face_list->d = grp_ptr->eqn[f].v[3];
926
                }
956
                }
927
                face_list->map[0] = &prepared->groups[group].vertices[v1].map;
957
                face_list->map[0] = &grp_ptr->map[v1];
928
                face_list->map[1] = &prepared->groups[group].vertices[v2].map;
958
                face_list->map[1] = &grp_ptr->map[v2];
929
                face_list->map[2] = &prepared->groups[group].vertices[v3].map;
959
                face_list->map[2] = &grp_ptr->map[v3];
930
                if (face_list->material!= NULL
960
                if (face_list->material != NULL
931
                    && face_list->material->identifier != NULL
961
                    && face_list->material->identifier != NULL
932
                    && face_list->material->identifier[0] == '!') {
962
                    && face_list->material->identifier[0] == '!') {
933
                    gPling_face = face_list;
963
                    gPling_face = face_list;
934
                }
964
                }
935
                face_list++;
965
                face_list++;
Line 1196... Line 1226...
1196
    return 0;
1226
    return 0;
1197
}
1227
}
1198
 
1228
 
1199
// IDA: int __usercall CompVert@<EAX>(int v1@<EAX>, int v2@<EDX>)
1229
// IDA: int __usercall CompVert@<EAX>(int v1@<EAX>, int v2@<EDX>)
1200
int CompVert(int v1, int v2) {
1230
int CompVert(int v1, int v2) {
1201
    //br_vertex* vl; // Pierre-Marie Baty -- unused variable
1231
    br_vertex* vl;
1202
    //br_vector3 tv; // Pierre-Marie Baty -- unused variable
1232
    br_vector3 tv;
1203
    //br_vector2 tv2; // Pierre-Marie Baty -- unused variable
1233
    br_vector2 tv2;
1204
    LOG_TRACE("(%d, %d)", v1, v2);
1234
    LOG_TRACE("(%d, %d)", v1, v2);
-
 
1235
 
-
 
1236
    if (v1 == v2) {
1205
    NOT_IMPLEMENTED();
1237
        return 1;
-
 
1238
    }
-
 
1239
    vl = gSelected_model->vertices;
-
 
1240
    BrVector3Sub(&tv, &vl[v1].p, &vl[v2].p);
-
 
1241
    if (BrVector3LengthSquared(&tv) > 1e-5f) {
-
 
1242
        return 0;
-
 
1243
    }
-
 
1244
    BrVector2Sub(&tv2, &vl[v1].map, &vl[v2].map);
-
 
1245
    if (BrVector2LengthSquared(&tv2) > 1e-5f) {
-
 
1246
        return 0;
-
 
1247
    }
-
 
1248
    return 1;
1206
}
1249
}
1207
 
1250
 
1208
// IDA: void __usercall SetFacesGroup(int pFace@<EAX>)
1251
// IDA: void __usercall SetFacesGroup(int pFace@<EAX>)
1209
void SetFacesGroup(int pFace) {
1252
void SetFacesGroup(int pFace) {
1210
    //int f; // Pierre-Marie Baty -- unused variable
1253
    //int f; // Pierre-Marie Baty -- unused variable
Line 1226... Line 1269...
1226
    NOT_IMPLEMENTED();
1269
    NOT_IMPLEMENTED();
1227
}
1270
}
1228
 
1271
 
1229
// IDA: void __usercall GetTilingLimits(br_vector2 *min@<EAX>, br_vector2 *max@<EDX>)
1272
// IDA: void __usercall GetTilingLimits(br_vector2 *min@<EAX>, br_vector2 *max@<EDX>)
1230
void GetTilingLimits(br_vector2* min, br_vector2* max) {
1273
void GetTilingLimits(br_vector2* min, br_vector2* max) {
1231
    //int f; // Pierre-Marie Baty -- unused variable
1274
    int f;
1232
    //int i; // Pierre-Marie Baty -- unused variable
1275
    int i;
1233
    //int j; // Pierre-Marie Baty -- unused variable
1276
    int j;
1234
    //br_vertex* verts; // Pierre-Marie Baty -- unused variable
1277
    br_vertex* verts;
1235
    //br_face* faces; // Pierre-Marie Baty -- unused variable
1278
    br_face* faces;
1236
    LOG_TRACE("(%p, %p)", min, max);
1279
    LOG_TRACE("(%p, %p)", min, max);
-
 
1280
 
-
 
1281
    verts = gSelected_model->vertices;
-
 
1282
    faces = gSelected_model->faces;
-
 
1283
    BrVector2Set(min, 32000.f, 32000.f);
-
 
1284
    BrVector2Set(max, -32000.f, -32000.f);
-
 
1285
    for (f = 0; f < gSelected_model->nfaces; f++) {
-
 
1286
        if (faces[f].material == gSub_material) {
-
 
1287
            for (i = 0; i < 3; i++) {
-
 
1288
                for (j = 0; j < 3; j++) {
-
 
1289
                    if (verts[faces[f].vertices[i]].map.v[j] < min->v[j]) {
-
 
1290
                        min->v[j] = verts[faces[f].vertices[i]].map.v[j];
1237
    NOT_IMPLEMENTED();
1291
                    }
-
 
1292
                    if (verts[faces[f].vertices[i]].map.v[j] > max->v[j]) {
-
 
1293
                        max->v[j] = verts[faces[f].vertices[i]].map.v[j];
-
 
1294
                    }
-
 
1295
                }
-
 
1296
            }
-
 
1297
        }
-
 
1298
    }
1238
}
1299
}
1239
 
1300
 
1240
// IDA: void __usercall Scale(int pD@<EAX>, int factor@<EDX>)
1301
// IDA: void __usercall Scale(int pD@<EAX>, int factor@<EDX>)
1241
void Scale(int pD, int factor) {
1302
void Scale(int pD, int factor) {
1242
    //br_vector2 min; // Pierre-Marie Baty -- unused variable
1303
    br_vector2 min;
1243
    //br_vector2 max; // Pierre-Marie Baty -- unused variable
1304
    br_vector2 max;
1244
    //int f; // Pierre-Marie Baty -- unused variable
1305
    int f;
1245
    //int v; // Pierre-Marie Baty -- unused variable
1306
    int v;
1246
    //br_scalar d; // Pierre-Marie Baty -- unused variable
1307
    br_scalar d;
1247
    //br_vertex* verts; // Pierre-Marie Baty -- unused variable
1308
    br_vertex* verts;
1248
    //br_face* faces; // Pierre-Marie Baty -- unused variable
1309
    br_face* faces;
1249
    LOG_TRACE("(%d, %d)", pD, factor);
1310
    LOG_TRACE("(%d, %d)", pD, factor);
-
 
1311
 
-
 
1312
    if (gSelected_model == NULL) {
-
 
1313
        return;
-
 
1314
    }
-
 
1315
    if (gSelected_model->nfaces != gNfaces) {
-
 
1316
        return;
-
 
1317
    }
-
 
1318
    verts = gSelected_model->vertices;
-
 
1319
    faces = gSelected_model->faces;
-
 
1320
    GetTilingLimits(&min, &max);
-
 
1321
    d = max.v[pD] - min.v[pD];
-
 
1322
    if (d <= 0.f || factor + d <= 0.f) {
-
 
1323
        return;
-
 
1324
    }
-
 
1325
    for (v = 0; v < gSelected_model->nvertices; v++) {
-
 
1326
        for (f = 0; f < gSelected_model->nfaces; f++) {
-
 
1327
            if (faces[f].material == gSub_material
-
 
1328
                    && (faces[f].vertices[0] == v || faces[f].vertices[1] == v || faces[f].vertices[2] == v)) {
-
 
1329
                verts[v].map.v[pD] = (factor + d) / d * verts[v].map.v[pD];
1250
    NOT_IMPLEMENTED();
1330
                break;
-
 
1331
            }
-
 
1332
        }
-
 
1333
    }
-
 
1334
    BrModelUpdate(gSelected_model, BR_MODU_ALL);
1251
}
1335
}
1252
 
1336
 
1253
// IDA: void __cdecl ScaleUpX()
1337
// IDA: void __cdecl ScaleUpX()
1254
void ScaleUpX(void) {
1338
void ScaleUpX(void) {
1255
    LOG_TRACE("()");
1339
    LOG_TRACE("()");
-
 
1340
 
1256
    NOT_IMPLEMENTED();
1341
    Scale(0, 1);
1257
}
1342
}
1258
 
1343
 
1259
// IDA: void __cdecl ScaleDnX()
1344
// IDA: void __cdecl ScaleDnX()
1260
void ScaleDnX(void) {
1345
void ScaleDnX(void) {
1261
    LOG_TRACE("()");
1346
    LOG_TRACE("()");
-
 
1347
 
1262
    NOT_IMPLEMENTED();
1348
    Scale(0, -1);
1263
}
1349
}
1264
 
1350
 
1265
// IDA: void __cdecl ScaleUpY()
1351
// IDA: void __cdecl ScaleUpY()
1266
void ScaleUpY(void) {
1352
void ScaleUpY(void) {
1267
    LOG_TRACE("()");
1353
    LOG_TRACE("()");
-
 
1354
 
1268
    NOT_IMPLEMENTED();
1355
    Scale(1, 1);
1269
}
1356
}
1270
 
1357
 
1271
// IDA: void __cdecl ScaleDnY()
1358
// IDA: void __cdecl ScaleDnY()
1272
void ScaleDnY(void) {
1359
void ScaleDnY(void) {
1273
    LOG_TRACE("()");
1360
    LOG_TRACE("()");
-
 
1361
 
1274
    NOT_IMPLEMENTED();
1362
    Scale(1, -1);
1275
}
1363
}
1276
 
1364
 
1277
// IDA: void __cdecl SelectFaceForward()
1365
// IDA: void __cdecl SelectFaceForward()
1278
void SelectFaceForward(void) {
1366
void SelectFaceForward(void) {
1279
    //br_vector3 dir; // Pierre-Marie Baty -- unused variable
1367
    br_vector3 dir;
1280
    LOG_TRACE("()");
1368
    LOG_TRACE("()");
-
 
1369
 
-
 
1370
    BrVector3Scale(&dir, (br_vector3*)&gProgram_state.current_car.car_master_actor->t.t.mat.m[2], -2.f);
1281
    NOT_IMPLEMENTED();
1371
    SelectFace(&dir);
1282
}
1372
}
1283
 
1373
 
1284
// IDA: void __cdecl SelectFaceDown()
1374
// IDA: void __cdecl SelectFaceDown()
1285
void SelectFaceDown(void) {
1375
void SelectFaceDown(void) {
1286
    //br_vector3 dir; // Pierre-Marie Baty -- unused variable
1376
    br_vector3 dir;
1287
    LOG_TRACE("()");
1377
    LOG_TRACE("()");
-
 
1378
 
-
 
1379
    BrVector3Scale(&dir, (br_vector3*)&gProgram_state.current_car.car_master_actor->t.t.look_up.up, -2.f);
1288
    NOT_IMPLEMENTED();
1380
    SelectFace(&dir);
1289
}
1381
}