-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCuboid.cs
72 lines (61 loc) · 2.62 KB
/
Cuboid.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
namespace TheraWii
{
class Cuboid
{
public Vector3 Scale;
public Vector3 Position;
public Vector3 color;
protected float aspectRatio;
protected Model cuboidModel;
protected Vector3 cameraPosition = new Vector3(0.0f, 0.0f, 10.0f);
protected GraphicsDeviceManager graphics;
protected ContentManager Content;
public Cuboid()
{
}
public Cuboid(GraphicsDeviceManager g, ContentManager c, Vector3 position, Vector3 scale, Color color)
{
this.Scale = scale;
this.Position = position;
this.color = color.ToVector3();
graphics = g;
Content = c;
aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
cuboidModel = Content.Load<Model>("Models\\cube");
}
public virtual void Draw()
{
// Copy any parent transforms.
Matrix[] transforms = new Matrix[cuboidModel.Bones.Count];
cuboidModel.CopyAbsoluteBoneTransformsTo(transforms);
// Draw the model. A model can have multiple meshes, so loop.
foreach (ModelMesh mesh in cuboidModel.Meshes)
{
// This is where the mesh orientation is set, as well as our camera and projection.
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.DiffuseColor = this.color;
effect.LightingEnabled = false;
//effect.DirectionalLight0.Direction = new Vector3(0.0f, 0.0f, 1.0f);
effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspective(0.2f, 0.2f, 1.0f, 1000.0f);
effect.World = transforms[mesh.ParentBone.Index]
//* Matrix.CreateRotationZ(MathHelper.ToRadians(30.0f))
* Matrix.CreateScale(0.5f * Scale.X, 0.5f * Scale.Y, 0.5f * Scale.Z)
* Matrix.CreateTranslation(Position)
;
}
// Draw the mesh, using the effects set above.
mesh.Draw();
}
}
}
}