/
Drawing1.cs
123 lines (111 loc) · 4.08 KB
/
Drawing1.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
/* SUPER SMASH BROS. BRAWL 3D MODEL VIEWER
* Programmers: Michael Yoon Huh (huhx0015), Steve Chou (azntofu2000/chou0069)
* Last Updated: 12/15/2011 */
namespace _3DPoringModel
{
// "ball" class. Code by azntofu2000.
public class ball
{
public Vector3 distance;
public float velocity;
public float acc;
public float time;
public bool isfalling;
public bool reverse;
public float Vinit;
public bool hasBounced;
public bool finishBouncing;
private int movementVector;
public int counter;
/// <summary>
/// Starting clockwise on the 3 o'clock position with a total of 8 vectors.
/// 0 = east
/// 1 = NE
/// 2 = North
/// 3 = NW
/// 4 = W
/// 5 = SW
/// 6 = S
/// 7 = SE
/// </summary>
public int Direction
{
get { return movementVector; }
set { movementVector = value; }
}
}
// "modelMatrix" class.
public class modelMatrix
{
public Matrix worldMatrix;
public Matrix projectionMatrix;
public Matrix viewMatrix;
public Matrix setWorld
{
get { return worldMatrix; }
set { worldMatrix = value; }
}
public Matrix setProjection
{
get { return projectionMatrix; }
set { projectionMatrix = value; }
}
public Matrix setView
{
get { return viewMatrix; }
set { viewMatrix = value; }
}
}
// "ModelObject" class.
public class ModelObject
{
public Model model;
public Texture2D[] textures;
public Vector3 startPos;
public Vector3 direction;
public ball gravity;
public Matrix matrix;
public Vector3 yloc;
}
// "Drawing": This is the drawing class for the Super Smash Bros. Brawl Model Viewer application. This class is responsible for drawing and animating the model.
public class Drawing : Microsoft.Xna.Framework.Game
{
// Ball motion global variables.
public float Scale = 0.5f;
// "DrawModel()": Draws the model and textures for the model.
public void DrawModel(modelMatrix modMatrix, ModelObject theModel)
{
Matrix[] transforms = new Matrix[theModel.model.Bones.Count];
theModel.model.CopyAbsoluteBoneTransformsTo(transforms);
int j = 0;
foreach (ModelMesh mesh in theModel.model.Meshes)
{
foreach (Effect currentEffect in mesh.Effects)
{
Matrix wMatrix = transforms[mesh.ParentBone.Index] * modMatrix.worldMatrix; // Model + motion.
//Matrix wMatrix = transforms[mesh.ParentBone.Index]; // Model draw only.
currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"]; // Specifies the loading of textures onto model.
currentEffect.Parameters["xWorld"].SetValue(wMatrix);
currentEffect.Parameters["xView"].SetValue(modMatrix.viewMatrix);
currentEffect.Parameters["xProjection"].SetValue(modMatrix.projectionMatrix);
currentEffect.Parameters["xEnableLighting"].SetValue(true); // Enables lighting.
currentEffect.Parameters["xLightDirection"].SetValue(new Vector3(3, -2, 5)); // Sets the direction of the light.
currentEffect.Parameters["xAmbient"].SetValue(0.5f);
currentEffect.Parameters["xTexture"].SetValue(theModel.textures[j++]); // Apply the textures.
}
mesh.Draw(); // Draws the mesh.
}
}
}
}