void csCameraBase::Correct (int n, float *vals[]) { if (vals == 0) return; if (vals[0] == 0) return; if (vals[1] == 0) return; float r; if (vals[2] != 0) { if (*vals[0] < *vals[1]) { r = *vals[2]; *vals[2] = *vals[0]; *vals[0] = r; } else { r = *vals[2]; *vals[2] = *vals[1]; *vals[1] = r; } } float angle; angle = (float)atan2 (*vals[1], *vals[0]); angle = (TWO_PI / n) * csQround (n * angle / TWO_PI); *vals[1] = csQsqrt ((*vals[0]) * (*vals[0]) + (*vals[1]) * (*vals[1])); Correct (n, vals + 1); r = *vals[1]; *vals[0] = r * (float)cos (angle); *vals[1] = r * (float)sin (angle); cameranr = cur_cameranr++; }
void csDecal::Initialize (iDecalTemplate * decalTemplate, const csVector3 & normal, const csVector3 & pos, const csVector3 & up, const csVector3 & right, float width, float height) { this->indexCount = 0; this->vertexCount = 0; this->currMesh = 0; this->decalTemplate = decalTemplate; this->normal = normal; this->pos = pos; this->width = width; this->height = height; radius = csQsqrt (width * width + height * height); invWidth = 1.0f / width; invHeight = 1.0f / height; this->up = up; this->right = right; life = 0; topPlaneDist = 0.0f; bottomPlaneDist = 0.0f; ClearRenderMeshes (); }
void csSphere::Union (const csVector3 &ocenter, float oradius) { // First calculate distance between centers of two spheres. float distance = csQsqrt (csSquaredDist::PointPoint (center, ocenter)); if (radius >= oradius + distance) // Sphere 2 is inside sphere 1 { } else if (oradius >= radius + distance) // Sphere 1 is inside sphere 2 { center = ocenter; radius = oradius; } else if (ABS (distance) < SMALL_EPSILON) { // Spheres very close to each other. Because the two tests above // succeeded the spheres are actually equal. So nothing has to be done. } else { csVector3 direction = (center - ocenter) / distance; center = (center + direction * radius + ocenter + direction * oradius) * 0.5f; radius = (radius + oradius + distance) * 0.5f; } }
void csPortalContainer::Prepare () { if (prepared) return; prepared = true; movable_nr = -1; // Make sure move stuff gets updated. movable_identity = false; data_nr++; csCompressVertex* vt = csVector3Array::CompressVertices (vertices); size_t i; for (i = 0 ; i < portals.GetSize () ; i++) { csPortal* prt = portals[i]; size_t j; csArray<int>& vidx = prt->GetVertexIndices (); csPoly3D poly; csBox3 box; box.StartBoundingBox (); for (j = 0 ; j < vidx.GetSize () ; j++) { if (vt) vidx[j] = (int)vt[vidx[j]].new_idx; poly.AddVertex (vertices[vidx[j]]); box.AddBoundingVertex (vertices[vidx[j]]); } float max_sqradius = 0; csVector3 center = box.GetCenter (); for (j = 0 ; j < vidx.GetSize () ; j++) { float sqdist = csSquaredDist::PointPoint (center, vertices[vidx[j]]); if (sqdist > max_sqradius) max_sqradius = sqdist; } prt->object_sphere = csSphere (center, csQsqrt (max_sqradius)); prt->SetObjectPlane (poly.ComputePlane ()); } delete[] vt; object_bbox.StartBoundingBox (); for (i = 0 ; i < vertices.GetSize () ; i++) object_bbox.AddBoundingVertex (vertices[i]); object_radius = csQsqrt (csSquaredDist::PointPoint ( object_bbox.Max (), object_bbox.Min ())) * 0.5f; }
void G2DTestSystemDriver::DrawLinePerf () { SetFont (fontItalic); WriteCentered (0,-16*4, white, -1, "LINE SLOPE AND PERFORMANCE TEST"); int w2 = myG2D->GetWidth () / 2; int colors [4] = { red, green, blue, yellow }; int a; for (a = 0; a < 360; a += 5) { float angle = (a * TWO_PI) / 360.0; float x = w2 + 80 * cos (angle); float y = 100 + 80 * sin (angle); myG2D->DrawLine (w2, 100, x, y, colors [a & 3]); } // Compute the size for the random lines box int sx = 0; int sw = myG2D->GetWidth (); int sy = myG2D->GetHeight () / 2; int sh = sy; myG2D->DrawBox (sx, sy + 16, sw, sh - 16, dsteel); SetFont (fontLarge); WriteCentered (0,-16*2, gray, -1, "Above this text you should see a uniformly hashed circle,"); WriteCentered (0,-16*1, gray, -1, "while below you should see some random lines, and the"); WriteCentered (0, 16*0, gray, -1, "measured line drawing performance in pixels per second."); // Test line drawing performance for 1/4 seconds sx += 20; sw -= 40; sy += 30; sh -= 40; csRandomGen rng (csGetTicks ()); csTicks start_time = csGetTicks (), delta_time; float pix_count = 0; do { for (a = 0; a < 5000; a++) { float x1 = sx + rng.Get () * sw; float y1 = sy + rng.Get () * sh; float x2 = sx + rng.Get () * sw; float y2 = sy + rng.Get () * sh; myG2D->DrawLine (x1, y1, x2, y2, colors [rng.Get (4)]); x2 = csQint (x2 - x1); y2 = csQint (y2 - y1); pix_count += csQsqrt (x2 * x2 + y2 * y2); } myG2D->PerformExtension ("flush"); delta_time = csGetTicks () - start_time; } while (delta_time < 500); pix_count = pix_count * (1000.0 / delta_time); WriteCentered (0, 16*1, green, black, " Performance: %20.1f pixels/second ", pix_count); }
iDecal * csDecalManager::CreateDecal (iDecalTemplate * decalTemplate, iSector * sector, const csVector3 & pos, const csVector3 & up, const csVector3 & normal, float width, float height, iDecal * oldDecal) { // compute the maximum distance the decal can reach float radius = csQsqrt (width * width + height * height) * 2.0f; if (!EnsureEngineReference ()) return 0; // get all meshes that could be affected by this decal csRef<iMeshWrapperIterator> it = engine->GetNearbyMeshes (sector, pos, radius, true); if (!it->HasNext ()) return 0; // calculate a valid orientation for the decal csVector3 n = normal.Unit (); csVector3 u = up.Unit (); csVector3 right = n % u; csVector3 correctUp = right % n; // create the decal and fill it with mesh geometry csDecal * decal = 0; if (oldDecal) { // we must ensure that this decal is actually active const size_t len = decals.GetSize (); for (size_t a = 0; a < len; ++a) { if (decals[a] != oldDecal) continue; decal = decals[a]; decals.DeleteIndexFast (a); break; } } if (!decal) decal = new csDecal (objectReg, this); csVector3 relPos; decal->Initialize (decalTemplate, n, pos, correctUp, right, width, height); decals.Push (decal); FillDecal (decal, it, pos, radius); return decal; }
bool StartMe::OnMouseMove (iEvent& ev) { if (rotationStatus == OVER_EXIT) return false; // Compute the angle and distance to the bottom right corner of the window csRef<iGraphics2D> g2d = csQueryRegistry<iGraphics2D> (GetObjectRegistry ()); float x = g2d->GetWidth () - csMouseEventHelper::GetX(&ev) - 104.0f; float y = g2d->GetHeight () - csMouseEventHelper::GetY(&ev) + 4.0f; float distance = csQsqrt (x * x + y * y); float angle = atan2 (y - 4.0f, x + 104.0f); float angleDistance = 1.0f - fabs (PI * 0.27f - angle) / (PI * 0.25f); distance -= angleDistance * 50.0f; // If the mouse is too far away then rotate at default speed if (distance < 170.0f || distance > 380.0f) { rotationStatus = ROTATE_NORMAL; rotationSpeed = DEFAULT_ROTATION_SPEED; return false; } // If the mouse is near the center then stop the rotation if (angle > PI * 0.166f && angle < PI * 0.333f) rotationStatus = ROTATE_SELECTING; // If the mouse is on the side, then rotate faster else { rotationStatus = ROTATE_SEARCHING; if (angle > PI * 0.333f) { float distance = angle - PI * 0.333f; rotationSpeed = - DEFAULT_ROTATION_SPEED * distance * 15.0f; } else { float distance = PI * 0.166f - angle; rotationSpeed = DEFAULT_ROTATION_SPEED * distance * 15.0f; } } return false; }
void csHazeMeshObject::SetupObject () { if (!initialized) { bbox.StartBoundingBox (origin); csVector3 pos; size_t l; int i; for(l=0; l<layers.GetSize (); l++) for(i=0; i<layers[l]->hull->GetVerticeCount(); i++) { layers[l]->hull->GetVertex(pos, i); bbox.AddBoundingVertex (pos); } radius = csQsqrt (csSquaredDist::PointPoint (bbox.Max (), bbox.Min ())); initialized = true; } }
void csMeshObject::GetRadius (float& radius, csVector3& center) { csBox3 b (GetObjectBoundingBox ()); radius = csQsqrt (csSquaredDist::PointPoint (b.Max (), b.Min ())) * 0.5f; center = b.GetCenter (); }