/* Copy one vector into another */ void vec_copy(vec_t dest, vec_t src) { int i; if (dest.d != src.d) { printf("[vec_copy] Mismatch in vector sizes\n"); return; } for (i = 0; i < dest.d; i++) { Vn(dest, i) = Vn(src, i); } }
vec_t vec_new_set(int d, double val) { vec_t v = vec_new(d); int i; for (i = 0; i < d; i++) Vn(v, i) = val; return v; }
/* * Run the whole workload. */ static void runit(unsigned numthinkers, unsigned numgrinders, unsigned numponggroups, unsigned ponggroupsize) { pid_t pids[numponggroups + 2]; time_t startsecs; unsigned long startnsecs; char buf[32]; unsigned i; tprintf("Running with %u thinkers, %u grinders, and %u pong groups " "of size %u each.\n", numthinkers, numgrinders, numponggroups, ponggroupsize); usem_init(&startsem, STARTSEM); createresultsfile(); forkem(numthinkers, nop, think, nop, 0, &pids[0]); forkem(numgrinders, nop, grind, nop, 1, &pids[1]); for (i=0; i<numponggroups; i++) { forkem(ponggroupsize, pong_prep, pong, pong_cleanup, i+2, &pids[i+2]); } usem_open(&startsem); tprintf("Forking done; starting the workload.\n"); __time(&startsecs, &startnsecs); Vn(&startsem, numthinkers + numgrinders + numponggroups * ponggroupsize); waitall(pids, numponggroups + 2); usem_close(&startsem); usem_cleanup(&startsem); openresultsfile(O_RDONLY); tprintf("--- Timings ---\n"); if (numthinkers > 0) { calcresult(0, startsecs, startnsecs, buf, sizeof(buf)); tprintf("Thinkers: %s\n", buf); } if (numgrinders > 0) { calcresult(1, startsecs, startnsecs, buf, sizeof(buf)); tprintf("Grinders: %s\n", buf); } for (i=0; i<numponggroups; i++) { calcresult(i+2, startsecs, startnsecs, buf, sizeof(buf)); tprintf("Pong group %u: %s\n", i, buf); } closeresultsfile(); destroyresultsfile(); }
/** @brief calculate the normals of all triangles (Tn) and the average normals of the vertices (N); average normals are averaged over all adjacent triangles that are in the triangle list or member of a strip */ void Mesh::computeNormals() { uint i; Vector a, b, c; Tn.resize(T.d0, 3); Tn.setZero(); Vn.resize(V.d0, 3); Vn.setZero(); //triangle normals and contributions for(i=0; i<T.d0; i++) { a.set(&V(T(i, 0), 0)); b.set(&V(T(i, 1), 0)); c.set(&V(T(i, 2), 0)); b-=a; c-=a; a=b^c; a.normalize(); Tn(i, 0)=a.x; Tn(i, 1)=a.y; Tn(i, 2)=a.z; Vn(T(i, 0), 0)+=a.x; Vn(T(i, 0), 1)+=a.y; Vn(T(i, 0), 2)+=a.z; Vn(T(i, 1), 0)+=a.x; Vn(T(i, 1), 1)+=a.y; Vn(T(i, 1), 2)+=a.z; Vn(T(i, 2), 0)+=a.x; Vn(T(i, 2), 1)+=a.y; Vn(T(i, 2), 2)+=a.z; } Vector d; for(i=0; i<Vn.d0; i++) { d.set(&Vn(i, 0)); Vn[i]()/=d.length(); } }
/* -------------------------------------------------------------------------------------------------- - check collision with stairs -------------------------------------------------------------------------------------------------- */ bool PlanesPhysicHandler::ColisionWithStair(const AABB & actorBB, const VECTOR &Speed, VECTOR &ModifiedSpeed) { float moveX = Speed.x; float moveZ = Speed.z; // calculate norm of speed VECTOR speedNorm = Speed.unit(); float startX = (actorBB.P.x+actorBB.E.x)/2.0f; float startZ = (actorBB.P.z+actorBB.E.z)/2.0f; std::vector<StairPlane>::const_iterator it = _stairs.begin(); std::vector<StairPlane>::const_iterator end = _stairs.end(); // for each stairs for(int i=0; it != end; ++it, ++i) { // project point to plane and check if we cross it float DotProduct=speedNorm.dot(it->Normal); // Determine If Ray Parallel To Plane if (abs(DotProduct) > 0.000001f) { // Find Distance To Collision Point float l2=(it->Normal.dot(it->C1-VECTOR(startX, actorBB.P.y, startZ)))/DotProduct; // Test If Collision Behind Start or after end if (l2 > 0 && l2 < Speed.length()) { float collionsX = startX + (speedNorm.x * l2); float collionsZ = startZ + (speedNorm.z * l2); if((collionsX >= it->minX) && (collionsX <= it->maxX)) { if((collionsZ >= it->minZ) && (collionsZ <= it->maxZ)) { VECTOR spmY(Speed.x, 0, Speed.z); VECTOR Vt(it->Normal.dot(spmY)*it->Normal); VECTOR Vn(spmY - Vt); ModifiedSpeed = Vn; return true; } } } } } return false; }
/* Scale the given vector with the given scalar (changing the * given vector) */ void vec_scale_inplace(double c, vec_t v) { int i; for (i = 0; i < v.d; i++) Vn(v, i) *= c; }