Graphics Reference
In-Depth Information
// Create the per environment map buffer (to store the 6
// ViewProjection matrices)
PerEnvMapBuffer = ToDispose(new Buffer(device,
Utilities.SizeOf<Matrix>() * 6 , ResourceUsage.Default,
BindFlags.ConstantBuffer, CpuAccessFlags.None,
ResourceOptionFlags.None, 0));
This completes the initialization of our cube map's Direct3D resources.
20. Still within the DynamicCubeMap class, we will create a new public method for
updating the current camera positions.
// Update camera position for cube faces
public void SetViewPoint(Vector3 camera)
{ // The LookAt targets for view matrices
var targets = new[] {
camera + Vector3.UnitX, // +X
camera - Vector3.UnitX, // -X
camera + Vector3.UnitY, // +Y
camera - Vector3.UnitY, // -Y
camera + Vector3.UnitZ, // +Z
camera - Vector3.UnitZ // -Z
};
// The "up" vector for view matrices
var upVectors = new[] {
Vector3.UnitY, // +X
Vector3.UnitY, // -X
-Vector3.UnitZ,// +Y
+Vector3.UnitZ,// -Y
Vector3.UnitY, // +Z
Vector3.UnitY, // -Z
};
// Create view and projection matrix for each face
for (int i = 0; i < 6; i++)
{
Cameras[i].View = Matrix.LookAtRH(camera,
targets[i],
upVectors[i]) * Matrix.Scaling(-1, 1, 1);
Cameras[i].Projection = Matrix.PerspectiveFovRH(
(float)Math.PI * 0.5f, 1.0f, 0.1f, 100.0f);
}
}
 
Search WWH ::




Custom Search