void cMatrix::TranslationMatrix (cVector vector) { Identity (); m_fields[0][3] = vector.x (); m_fields[1][3] = vector.y (); m_fields[2][3] = vector.z (); }
void cMatrix::RotationMatrix (cVector axis, float angle) // Creates a rotation matrix { float V[3]; int i; axis.Normalize (); for (i = 0; i < 3; i++) V[i] = axis.field (i); float c = cos (angle); float c1 = 1.0f - c; float s = sin (angle); m_fields[0][0] = V[0] * V[0] * c1 + c; m_fields[1][0] = V[0] * V[1] * c1 - V[2] * s; m_fields[2][0] = V[0] * V[2] * c1 + V[1] * s; m_fields[0][1] = V[1] * V[0] * c1 + V[2] * s; m_fields[1][1] = V[1] * V[1] * c1 + c; m_fields[2][1] = V[1] * V[2] * c1 - V[0] * s; m_fields[0][2] = V[2] * V[0] * c1 - V[1] * s; m_fields[1][2] = V[2] * V[1] * c1 + V[0] * s; m_fields[2][2] = V[2] * V[2] * c1 + c; m_fields[3][3] = 1.0f; for (i = 0; i < 3; i++) { // fill rest with 0.0 m_fields[i][3] = 0.0f; m_fields[3][i] = 0.0f; } }
cVector cMatrix::ApplyRotation (cVector vector) { cVector vectemp; for (int i = 0; i < 3; i++) vectemp.setField (i, m_fields[i][0] * vector.x () + m_fields[i][1] * vector.y () + m_fields[i][2] * vector.z ()); return vectemp; }
void cCritterViewer::setViewpoint(cVector toviewer, cVector lookatpoint, BOOL trytoseewholeworld) { //First do some default setup stuff _fieldofviewangle = cCritterViewer::STARTFIELDOFVIEWANGLE; setSpeed(0.0); #ifndef THREEDVECTORS //not THREEDVECTORS means the 2D case. _attitude = cMatrix(cVector2(1.0, 0.0), cVector2(0.0, 1.0), _position); #else //THREEDVECTORS _attitude = cMatrix(-cVector::ZAXIS, -cVector::XAXIS, cVector::YAXIS, cVector::ZEROVECTOR); /* To get a reasonable default orientation, we arrange the viewer axes so that: viewer x axis = world -z axis, viewer y axis = world -x axis, viewer z axis = world y axis. We pick this orientation so that if the viewer moves "forward" (along its tangent vector) it moves towards the world. (We correct the mismatch between the coordinate systems in the cCritterViewer::loadViewMatrix method, which has a long comment about this.) Note that we will adjust _position (fourth column) later in this call with a moveTo, also we may rotate the _attitude a bit. */ if (!_perspective) //Ortho view, simply move up. { _proportionofworldtoshow = 1.0; //Show all of a flat world. moveTo(lookatpoint + cCritterViewer::ORTHOZOFFSET * cVector::ZAXIS); // Get above the world _maxspeed = _maxspeedstandard = 0.5 * cCritterViewer::ORTHOZOFFSET; //Mimic perspective case. } else //_perspective { if (toviewer.isPracticallyZero()) //Not usable, so pick a real direction. toviewer = cVector::ZAXIS; //Default is straight up. if (trytoseewholeworld) /* Treat toviewer as a direction, and back off in that direction enough to see the whole world */ { toviewer.normalize(); //Make it a unit vector. _proportionofworldtoshow = cCritterViewer::PROPORTIONOFWORLDTOSHOW; //Trying to show all of a world when flying around it, often leaves too big a space around it. Real furthestcornerdistance = pgame()->border().maxDistanceToCorner(lookatpoint); Real tanangle = tan(_fieldofviewangle/2.0); /* We work with half the fov in this calculation, the tanangle will be the ratio of visible distance to distance above the world, that is, tanangle = dr/dz, where Our dr is _proportionofworldtoshow * furthestcornerdistance, and our dz is the unknown seeallz height we need to back off to. Swap tangangle and dz to get the next formula. */ ASSERT(tanangle); Real seeallz = _proportionofworldtoshow * furthestcornerdistance / tanangle; moveTo(lookatpoint + seeallz * toviewer); } else /*Not trytoseewholeworld. In this case we don't normalize toviewer, instead we treat it as a displacment from the lookatpoint. */ moveTo(lookatpoint + toviewer); lookAt(lookatpoint); _maxspeed = _maxspeedstandard = 0.5 * (position()-lookatpoint).magnitude(); /* Define the speed like this so it typically takes two seconds (1/0.5) to fly in to lookatpoint. */ _lastgoodplayeroffset = position() - pgame()->pplayer()->position(); } #endif //THREEDVECTORS case }
void cGraphicsMFC::vectorToPixel(cVector position, int &xpix, int &ypix, Real &zbuff) { /* I have to use a viewercorrection like in cGraphicsMFC::pixelToVector*/ int tempx, tempy; cVector viewercorrection = _matrix.lastColumn(); position += viewercorrection; _realpixelconverter.realToPixel(position.x(), position.y(), &tempx, &tempy); xpix = tempx; ypix = tempy; zbuff = 0.0; }
void cDvbSubtitleBitmaps::Draw(cOsd *Osd) { bool Scale = !(DoubleEqual(osdFactorX, 1.0) && DoubleEqual(osdFactorY, 1.0)); bool AntiAlias = true; if (Scale && osdFactorX > 1.0 || osdFactorY > 1.0) { // Upscaling requires 8bpp: int Bpp[MAXOSDAREAS]; for (int i = 0; i < numAreas; i++) { Bpp[i] = areas[i].bpp; areas[i].bpp = 8; } if (Osd->CanHandleAreas(areas, numAreas) != oeOk) { for (int i = 0; i < numAreas; i++) Bpp[i] = areas[i].bpp = Bpp[i]; AntiAlias = false; } } if (Osd->SetAreas(areas, numAreas) == oeOk) { for (int i = 0; i < bitmaps.Size(); i++) { cBitmap *b = bitmaps[i]; if (Scale) b = b->Scaled(osdFactorX, osdFactorY, AntiAlias); Osd->DrawBitmap(int(round(b->X0() * osdFactorX)), int(round(b->Y0() * osdFactorY)), *b); if (b != bitmaps[i]) delete b; } Osd->Flush(); } }
cVector cVector::cross(cVector& in){ sVector input = in.getVectorCoord(); cVector ret = cVector(((m_sVectorData->y * input.z) - (m_sVectorData->z * input.y)), ((m_sVectorData->z * input.x) - (m_sVectorData->x * input.z)), ((m_sVectorData->x * input.y) - (m_sVectorData->y * input.x))); return ret; }
void AddExcludes(pxnode pExcludes, cVector<cDetectExclude>& excludes, const char* pszProfile) { if (!pExcludes) return; for (pxnode pExclude = pExcludes->first_child; pExclude; pExclude = pExclude->next) { if (pExclude->type != SBVT_STRING || !pExclude->pdata) continue; cStrObj path; path.assign(pExclude->pdata, cCP_UNICODE, pExclude->data_size); bool bFound = false; for (tDWORD i = 0; i < excludes.size(); ++i) { cDetectExclude& exclude = excludes[i]; if (exclude.m_bEnable && (exclude.m_nTriggers & cDetectExclude::fObjectMask) && exclude.m_Object.m_strMask == path) { if (exclude.m_aTaskList.find(pszProfile) == exclude.m_aTaskList.npos) exclude.m_aTaskList.push_back(pszProfile); bFound = true; break; } } if (bFound) continue; cDetectExclude exclude; exclude.m_nTriggers |= cDetectExclude::fTaskList; exclude.m_Object.m_bRecurse = (!path.empty() && (path[path.length()-1] == '\\')) ? cTRUE : cFALSE; exclude.m_Object.m_strMask = path; exclude.m_aTaskList.push_back(pszProfile); excludes.push_back(exclude); } }
cVector build_condensation(const WorkSpaceGraph &graph) { vVector top_sort = topolog_sort< WorkSpaceGraph >(graph); in_sort.clear(); out_sort.clear(); used.clear(); std::for_each(top_sort.rbegin(), top_sort.rend(), [&cond, &used, &in_sort, this] (const Vertex &v) { if (used.find(v) == used.end()) { this->dfs< Transposed >(v); cond.push_back(vSet(in_sort.begin(), in_sort.end())); in_sort.clear(); } }); return cond; }
float cVector::dot(cVector& in){ sVector input = in.getVectorCoord(); return (m_sVectorData->x * input.x) + (m_sVectorData->y * input.y) + (m_sVectorData->z*input.z); }
cVector cVector::sub(cVector& in){ sVector a = in.getVectorCoord(); cVector ret = cVector((-a.x) + m_sVectorData->x, (-a.y) + m_sVectorData->y, (-a.z) + m_sVectorData->z); return ret; }
cVector cVector::add(cVector& in){ sVector a = in.getVectorCoord(); cVector ret = cVector(a.x + m_sVectorData->x, a.y + m_sVectorData->y, a.z + m_sVectorData->z); return ret; }
bool cVector::equal(cVector& in){ float origin = this->length(); float comp = in.length(); if ((origin - comp) * (origin - comp) <= EPSILON*EPSILON) return true; else return false; }
cVector cVector::operator-(cVector& v){ sVector a = v.getVectorCoord(); cVector ret = cVector((-a.x) + m_sVectorData->x, (-a.y) + m_sVectorData->y, (-a.z) + m_sVectorData->z); return ret; }
void cParticle::SetAcceleration (cVector vector) { vec_acc[0] = vector.x (); vec_acc[1] = vector.y (); vec_acc[2] = vector.z (); }
void cDvbSubtitleBitmaps::AddBitmap(cBitmap *Bitmap) { bitmaps.Append(Bitmap); }
void cVector::CrossProduct (cVector vector1, cVector vector2) { Set (vector1.y () * vector2.z () - vector1.z () * vector2.y (), // = x vector1.z () * vector2.x () - vector1.x () * vector2.z (), // = y vector1.x () * vector2.y () - vector1.y () * vector2.x () // = z ); }
float cVector::DotProduct (cVector vector) { return x () * vector.x () + y () * vector.y () + z () * vector.z (); }
cVector cVector::operator+(cVector& v){ sVector a = v.getVectorCoord(); cVector ret = cVector(a.x + m_sVectorData->x, a.y + m_sVectorData->y, a.z + m_sVectorData->z); return ret; }
void cParticle::Accelerate (cVector vector) { vec_speed[0] += vector.x (); vec_speed[1] += vector.y (); vec_speed[2] += vector.z (); }