Subversion Repositories Games.Carmageddon

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 pmbaty 1
#include "plane.h"
2
#include "CORE/STD/brmath.h"
3
#include "harness/trace.h"
4
#include <math.h>
5
 
6
// IDA: br_int_32 __cdecl BrPlaneEquation(br_vector4 *eqn, br_vector3 *v0, br_vector3 *v1, br_vector3 *v2)
7
br_int_32 BrPlaneEquation(br_vector4* eqn, br_vector3* v0, br_vector3* v1, br_vector3* v2) {
8
    //br_vector3 a; // Pierre-Marie Baty -- unused variable
9
    //br_vector3 b; // Pierre-Marie Baty -- unused variable
10
    float ax;
11
    float ay;
12
    float az;
13
    float bx;
14
    float by;
15
    float bz;
16
    float nx;
17
    float ny;
18
    float nz;
19
    float d;
20
    float l;
21
 
22
    ax = v1->v[0] - v0->v[0];
23
    ay = v1->v[1] - v0->v[1];
24
    az = v1->v[2] - v0->v[2];
25
    bx = v2->v[0] - v0->v[0];
26
    by = v2->v[1] - v0->v[1];
27
    bz = v2->v[2] - v0->v[2];
28
    nx = ay * bz - az * by;
29
    ny = az * bx - ax * bz;
30
    nz = ax * by - ay * bx;
31
    l = nx * nx + ny * ny + nz * nz;
32
    l = BrFloatSqrt(l);
33
    if (isnan(l)) {
34
        nx = 0.f;
35
        ny = 0.f;
36
        nz = 1.f;
37
    } else {
38
        nx = nx * (1.f / l);
39
        ny = ny * (1.f / l);
40
        nz = nz * (1.f / l);
41
    }
42
    d = nx * v0->v[0] + ny * v0->v[1] + nz * v0->v[2];
43
    eqn->v[0] = nx;
44
    eqn->v[1] = ny;
45
    eqn->v[2] = nz;
46
    eqn->v[3] = d;
47
    return !isnan(l);
48
}