void AvatarTest::CreateRoom () { // Creating the background // First we make a primitive for our geometry. CS::Geometry::DensityTextureMapper bgMapper (0.3f); CS::Geometry::TesselatedBox bgBox (csVector3 (-4000), csVector3 (4000)); bgBox.SetMapper (&bgMapper); bgBox.SetFlags (CS::Geometry::Primitives::CS_PRIMBOX_INSIDE); // Now we make a factory and a mesh at once. csRef<iMeshWrapper> background = CS::Geometry::GeneralMeshBuilder::CreateFactoryAndMesh (engine, room, "background", "background_factory", &bgBox); csRef<iMaterialWrapper> bgMaterial = CS::Material::MaterialBuilder::CreateColorMaterial (GetObjectRegistry (), "background", csColor (0.398f)); background->GetMeshObject()->SetMaterialWrapper (bgMaterial); // Set up of the physical collider for the roof if (physicsEnabled) dynamicSystem->AttachColliderPlane (csPlane3 (csVector3 (0.0f, 1.0f, 0.0f), 0.0f), 10.0f, 0.0f); // Creating lights csRef<iLight> light; iLightList* ll = room->GetLights (); // This light is for the background // TODO: putting instead the following line creates a black background, otherwise it is grey // the behavior doesn't persist if the other lights are removed //light = engine->CreateLight(0, csVector3(1, 1, -1), 9000, csColor (1)); light = engine->CreateLight(0, csVector3(1, 1, 0), 9000, csColor (1)); light->SetAttenuationMode (CS_ATTN_NONE); ll->Add (light); // Other lights light = engine->CreateLight (0, csVector3 (3, 0, 0), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); light = engine->CreateLight (0, csVector3 (-3, 0, 0), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); light = engine->CreateLight (0, csVector3 (0, 0, -3), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); light = engine->CreateLight (0, csVector3 (0, 0, 3), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); light = engine->CreateLight (0, csVector3 (0, -3, 0), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); engine->Prepare (); CS::Lighting::SimpleStaticLighter::ShineLights (room, engine, 4); }
void csDecal::BeginMesh(iMeshWrapper * mesh) { currMesh = 0; // check if InitializePosition has been called with decent parameters if (width <= 0.01f || height <= 0.01f) return; // check if we hit our maximum allowed triangles if (indexCount >= CS_DECAL_MAX_TRIS_PER_DECAL * 3) return; firstIndex = indexCount; const csReversibleTransform& trans = mesh->GetMovable ()->GetFullTransform (); localNormal = trans.Other2ThisRelative (normal); localUp = trans.Other2ThisRelative (up); localRight = trans.Other2ThisRelative (right); vertOffset = localNormal * decalTemplate->GetDecalOffset (); relPos = trans.Other2This (pos); if (decalTemplate->HasClipping ()) { // up clipPlanes[0] = csPlane3 (-localUp, -height*0.5f + localUp * relPos); // down clipPlanes[1] = csPlane3 (localUp, -height*0.5f - localUp * relPos); // left clipPlanes[2] = csPlane3 (-localRight, -width*0.5f + localRight * relPos); // right clipPlanes[3] = csPlane3 (localRight, -width*0.5f - localRight * relPos); numClipPlanes = 4; // top if (decalTemplate->HasTopClipping ()) { topPlaneDist = decalTemplate->GetTopClippingScale () * radius; clipPlanes[numClipPlanes++] = csPlane3 (-localNormal, -topPlaneDist + localNormal * relPos); } // bottom if (decalTemplate->HasBottomClipping ()) { bottomPlaneDist = decalTemplate->GetBottomClippingScale () * radius; clipPlanes[numClipPlanes++] = csPlane3 (localNormal, -bottomPlaneDist - localNormal * relPos); } } // we didn't encounter any errors, so validate the current mesh currMesh = mesh; }
void csBSPTree::Build (CS::TriangleIndicesStream<int>& triangles, const csVector3* vertices) { const size_t triComponents = triangles.GetRemainingComponents(); csDirtyAccessArray<csPlane3> planes ((triComponents+2)/3); csArray<int> triidx; csDirtyAccessArray<csTriangle> tris ((triComponents+2)/3); while (triangles.HasNext()) { CS::TriangleT<int> t (triangles.Next()); planes.Push (csPlane3 (vertices[t.a], vertices[t.b], vertices[t.c])); triidx.Push (int (tris.Push (t))); } Build (tris.GetArray(), planes.GetArray(), tris.GetSize(), vertices, triidx); }
//--------------------------------------------------------------------------- csPlane3 csTransform::Other2This (const csPlane3 &p) const { csVector3 newnorm = m_o2t * p.norm; // let N represent norm <A,B,C>, and X represent point <x,y,z> // // Old plane equation: N*X + D = 0 // There exists point X = <r*A,r*B,r*C> = r*N which satisfies the // plane equation. // => r*(N*N) + D = 0 // => r = -D/(N*N) // // New plane equation: N'*X' + D' = 0 // If M is the transformation matrix, and V the transformation vector, // N' = M*N, and X' = M*(X-V). Assume that N' is already calculated. // => N'*(M*(X-V)) + D' = 0 // => D' = -N'*(M*X) + N'*(M*V) // = -N'*(M*(r*N)) + N'*(M*V) // = -r*(N'*N') + N'*(M*V) = D*(N'*N')/(N*N) + N'*(M*V) // Since N' is a rotation of N, (N'*N') = (N*N), thus // D' = D + N'*(M*V) // return csPlane3 (newnorm, p.DD + newnorm * (m_o2t * v_o2t)); }
csPlane3 csTransform::Other2ThisRelative (const csPlane3 &p) const { csVector3 newnorm = m_o2t * p.norm; return csPlane3 (newnorm, p.DD); }
csPlane3 csReversibleTransform::This2OtherRelative (const csPlane3 &p) const { csVector3 newnorm = m_t2o * p.norm; return csPlane3 (newnorm, p.DD); }
//--------------------------------------------------------------------------- csPlane3 csReversibleTransform::This2Other (const csPlane3 &p) const { csVector3 newnorm = m_t2o * p.norm; return csPlane3 (newnorm, p.DD - p.norm * (m_o2t * v_o2t)); }