static bool GetPosOrient(const SpaceStationType::TMapBayIDMat &bayMap, const int stage, const double t, const vector3d &from, SpaceStationType::positionOrient_t &outPosOrient, const Ship *ship) { bool gotOrient = false; vector3d toPos; const SpaceStationType::TMapBayIDMat::const_iterator stageDataIt = bayMap.find( stage ); const bool bHasStageData = (stageDataIt != bayMap.end()); assert(bHasStageData); if (bHasStageData) { const matrix4x4f &mt = stageDataIt->second; outPosOrient.xaxis = vector3d(mt.GetOrient().VectorX()).Normalized(); outPosOrient.yaxis = vector3d(mt.GetOrient().VectorY()).Normalized(); outPosOrient.zaxis = vector3d(mt.GetOrient().VectorZ()).Normalized(); toPos = vector3d(mt.GetTranslate()); gotOrient = true; } if (gotOrient) { vector3d pos = vlerp(t, from, toPos); outPosOrient.pos = pos; } return gotOrient; }
void draw_line( texture *tx, vector *from, vector *to, pixel color ) { vector line, here; float t, length; size_t row, col; vcopy_as(&line, to); vsub_from(&line, from); line.z = 0; length = vmag(&line); for (t = 0; t < 1; t += LINE_DRAWING_RESOLUTION / length) { vlerp(from, to, t, &here); col = (size_t) here.x; row = (size_t) here.y; if ( ((col % tx->width) == col) && ((row % tx->height) == row) ) { tx_set_px(tx, color, col, row); } } }
static float distPtSegSqr(const float* pt, const float* sp, const float* sq) { float t; closestPtPtSeg(pt, sp,sq, t); float np[2]; vlerp(np, sp,sq, t); return vdistsqr(pt,np); }