public Cube4D(Vector3 origin1, Vector3 origin2, float size1, float size2) { // z negative (back) points var a1 = new Vector4(origin1.X - size1, origin1.Y - size1, origin1.Z - size1, 0); var a2 = new Vector4(origin2.X - size2, origin2.Y - size2, origin2.Z - size2, 1); var b1 = new Vector4(origin1.X - size1, origin1.Y + size1, origin1.Z - size1, 0); var b2 = new Vector4(origin2.X - size2, origin2.Y + size2, origin2.Z - size2, 1); var c1 = new Vector4(origin1.X + size1, origin1.Y - size1, origin1.Z - size1, 0); var c2 = new Vector4(origin2.X + size2, origin2.Y - size2, origin2.Z - size2, 1); var d1 = new Vector4(origin1.X + size1, origin1.Y + size1, origin1.Z - size1, 0); var d2 = new Vector4(origin2.X + size2, origin2.Y + size2, origin2.Z - size2, 1); // z positive (front) points var e1 = new Vector4(origin1.X - size1, origin1.Y - size1, origin1.Z + size1, 0); var e2 = new Vector4(origin2.X - size2, origin2.Y - size2, origin2.Z + size2, 1); var f1 = new Vector4(origin1.X - size1, origin1.Y + size1, origin1.Z + size1, 0); var f2 = new Vector4(origin2.X - size2, origin2.Y + size2, origin2.Z + size2, 1); var g1 = new Vector4(origin1.X + size1, origin1.Y - size1, origin1.Z + size1, 0); var g2 = new Vector4(origin2.X + size2, origin2.Y - size2, origin2.Z + size2, 1); var h1 = new Vector4(origin1.X + size1, origin1.Y + size1, origin1.Z + size1, 0); var h2 = new Vector4(origin2.X + size2, origin2.Y + size2, origin2.Z + size2, 1); /* var rand = new Random(); a1 *= (float)(rand.NextDouble() * 0.5 + 0.5); a2 *= (float)(rand.NextDouble() * 0.5 + 0.5); b1 *= (float)(rand.NextDouble() * 0.5 + 0.5); b2 *= (float)(rand.NextDouble() * 0.5 + 0.5); c1 *= (float)(rand.NextDouble() * 0.5 + 0.5); c2 *= (float)(rand.NextDouble() * 0.5 + 0.5); d1 *= (float)(rand.NextDouble() * 0.5 + 0.5); d2 *= (float)(rand.NextDouble() * 0.5 + 0.5); e1 *= (float)(rand.NextDouble() * 0.5 + 0.5); e2 *= (float)(rand.NextDouble() * 0.5 + 0.5); f1 *= (float)(rand.NextDouble() * 0.5 + 0.5); f2 *= (float)(rand.NextDouble() * 0.5 + 0.5); g1 *= (float)(rand.NextDouble() * 0.5 + 0.5); g2 *= (float)(rand.NextDouble() * 0.5 + 0.5); h1 *= (float)(rand.NextDouble() * 0.5 + 0.5); h2 *= (float)(rand.NextDouble() * 0.5 + 0.5); */ // faces back = new Quad4D(c1, c2, d1, d2, a1, a2, b1, b2); front = new Quad4D(e1, e2, f1, f2, g1, g2, h1, h2); top = new Quad4D(f1, f2, b1, b2, h1, h2, d1, d2); bottom = new Quad4D(a1, a2, e1, e2, c1, c2, g1, g2); left = new Quad4D(a1, a2, b1, b2, e1, e2, f1, f2); right = new Quad4D(g1, g2, h1, h2, c1, c2, d1, d2); }
protected override void Initialize() { primitives[0] = new Cube3D(new Vector3(-2, 1, -4), new Vector3(4, 2, 5)); primitives[1] = new Cube3D(new Vector3(-2, -1, -4), new Vector3(1, 2, 5)); primitives[2] = new Cube3D(new Vector3(1, -1, -4), new Vector3(1, 2, 5)); primitives[3] = new Quad4D( new Vector4(-1, -1, 1, 0), new Vector4(-1, -1, -4, 1), new Vector4(-1, 1, 1, 0), new Vector4(-1, 1, -4, 1), new Vector4(1, -1, 1, 0), new Vector4(1, -1, -4, 1), new Vector4(1, 1, 1, 0), new Vector4(1, 1, -4, 1) ); camera = new Vector3(0, 0, 5); View = Matrix.CreateLookAt(camera, Vector3.Zero, Vector3.Up); Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, 4.0f / 3.0f, 1, 500); base.Initialize(); }