MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FindHitpointUV

Function FindHitpointUV

physics/collide.cpp:930–976  ·  view source on GitHub ↗

finds the uv coords of the given point on the given seg & side fills in u & v. if l is non-NULL fills it in also

Source from the content-addressed store, hash-verified

928// finds the uv coords of the given point on the given seg & side
929// fills in u & v. if l is non-NULL fills it in also
930void FindHitpointUV(float *u, float *v, vector *point, room *rp, int facenum) {
931 face *fp = &rp->faces[facenum];
932 int ii, jj;
933 vec2d pnt[3], checkp, vec0, vec1;
934 float *t;
935 float k0, k1;
936 int i;
937
938 // 1. find what plane to project this wall onto to make it a 2d case
939
940 GetIJ(&fp->normal, &ii, &jj);
941
942 // 2. compute u,v of intersection point
943
944 // Copy face points into 2d verts array
945 for (i = 0; i < 3; i++) {
946 t = &rp->verts[fp->face_verts[i]].x;
947 pnt[i].i = t[ii];
948 pnt[i].j = t[jj];
949 }
950 t = &point->x;
951 checkp.i = t[ii];
952 checkp.j = t[jj];
953
954 // vec from 1 -> 0
955 vec0.i = pnt[0].i - pnt[1].i;
956 vec0.j = pnt[0].j - pnt[1].j;
957
958 // vec from 1 -> 2
959 vec1.i = pnt[2].i - pnt[1].i;
960 vec1.j = pnt[2].j - pnt[1].j;
961
962 k1 = -((cross(&checkp, &vec0) + cross(&vec0, &pnt[1])) / cross(&vec0, &vec1));
963 if (fabsf(vec0.i) > fabsf(vec0.j))
964 k0 = ((-k1 * vec1.i) + checkp.i - pnt[1].i) / vec0.i;
965 else
966 k0 = ((-k1 * vec1.j) + checkp.j - pnt[1].j) / vec0.j;
967
968 // mprintf(0," k0,k1 = %x,%x\n",k0,k1);
969
970 *u = fp->face_uvls[1].u + (k0 * (fp->face_uvls[0].u - fp->face_uvls[1].u)) +
971 (k1 * (fp->face_uvls[2].u - fp->face_uvls[1].u));
972 *v = fp->face_uvls[1].v + (k0 * (fp->face_uvls[0].v - fp->face_uvls[1].v)) +
973 (k1 * (fp->face_uvls[2].v - fp->face_uvls[1].v));
974
975 // mprintf(0," u,v = %x,%x\n",*u,*v);
976}
977
978// Creates some effects where a weapon has collided with a wall
979void DoWallEffects(object *weapon, int surface_tmap) {

Callers 1

BreakGlassFaceFunction · 0.85

Calls 1

GetIJFunction · 0.85

Tested by

no test coverage detected