AG LAB FILE Sakshi Gupta
AG LAB FILE Sakshi Gupta
(B.Sc. IT)
Animation Gaming Manual
B.Sc. IT Sem - 5
Name-Sakshi Gupta
1
AMITY UNIVERSITY CHHATTISGARH
Batch 2021-2024
2
1. Practical No. 1:
Aim: Setup DirectX 11, Window Framework and Initialize Direct3D Device
In this practical we are just learning the window framework and initializing a
Direct3D device.
Step 1:
i) Create new project, and select “Windows Forms Application”, select .NET
Framework as 2.0
in Visuals C#.
ii) Right Click on properties Click on open click on build Select Platform Target
and Select x86.
Step 2: Click on View Code of Form 1.
Step 3:
Go to Solution Explorer, right click on project name, and select Add Reference.
Click on Browse
and select the given .dll files which are “Microsoft.DirectX”,
“Microsoft.DirectX.Direct3D”, and
“Microsoft.DirectX.DirectX3DX”.
Step 4:
Go to Properties Section of Form, select Paint in the Event List and enter as
Form1_Paint.
Step 5:
Edit the Form’s C# code file. Namespace must be as same as your project name.
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
3
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GP_P1
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
public void InitDevice()
{
PresentParameterspp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing, pp);
}
private void Render()
{
device.Clear(ClearFlags.Target, Color.Orange, 0, 1);
device.Present();
}
4
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
Step 6: Click on Start. And here is the output. We have initialized 3D Device.
Output:
2. Practical No. 2:
Aim: Draw a triangle using Direct3D 11
Solution:
using System;
5
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GP_P2
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
private void InitDevice()
{
PresentParameterspp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing, pp);
}
private void Render()
6
{
CustomVertex.TransformedColored[] vertexes = new
CustomVertex.TransformedColored[3];
vertexes[0].Position = new Vector4(240, 110, 0, 1.0f);//first point
vertexes[0].Color = System.Drawing.Color.FromArgb(0, 255, 0).ToArgb();
vertexes[1].Position = new Vector4(380, 420, 0, 1.0f);//second point
vertexes[1].Color = System.Drawing.Color.FromArgb(0, 0, 255).ToArgb();
vertexes[2].Position = new Vector4(110, 420, 0, 1.0f);//third point
vertexes[2].Color = System.Drawing.Color.FromArgb(255, 0, 0).ToArgb();
device.Clear(ClearFlags.Target, Color.CornflowerBlue, 1.0f, 0);
device.BeginScene();
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertexes);
device.EndScene();
device.Present();
}
private void Form1_Load(object sender, EventArgs e) { }
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
Output:
7
3. Practical No. 3:
Aim: Texture the triangle using Direct3D 11
Solution:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace Gp_prac3
{
public partial class Form1 : Form
8
{
private Microsoft.DirectX.Direct3D.Device device;
privateCustomVertex.PositionTextured[] vertex = new
CustomVertex.PositionTextured[3];
private Texture texture;
public Form1()
{
InitializeComponent();
InitDevice();
}
private void InitDevice()
{
PresentParameterspp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0,DeviceType .Hardware ,this,
CreateFlags.HardwareVertexProcessing, pp);
device.Transform.Projection = Matrix.PerspectiveFovLH(3.14f / 4,
device.Viewport.Width /
device.Viewport.Height, 1f, 1000f);
device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 20), new
Vector3(),
new Vector3(0, 1, 0));
device.RenderState.Lighting = false;
vertex[0] = new CustomVertex.PositionTextured(new Vector3(0, 0, 0), 0, 0);
vertex[1] = new CustomVertex.PositionTextured(new Vector3(5, 0, 0), 0, 1);
vertex[2] = new CustomVertex.PositionTextured(new Vector3(0, 5, 0),-1, 1);
texture=new Texture (device,new Bitmap ("E:\\TYCS\\images\\img1.jpg"), 0,
Pool.Managed );
9
}
private void Form1_Load(Object sender, EventArgs e)
{}
private void Form1_Paint(Object sender, PaintEventArgs e)
{
device.Clear(ClearFlags.Target, Color.CornflowerBlue, 1, 0);
device.BeginScene();
device.SetTexture(0,texture);
device.VertexFormat = CustomVertex.PositionTextured.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList, vertex.Length / 3, vertex);
device.EndScene();
device.Present();
}
}
} Output:
4. Practical No. 4:
Aim: Loading models into DirectX 11 and rendering
using System;
10
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GP_P5_Loading_Model
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
Microsoft.DirectX.Direct3D.Texture texture;
Microsoft.DirectX.Direct3D.Font font;
public Form1()
{
InitializeComponent();
InitDevice();
InitFont();
LoadTexture();
}
private void InitFont()
{
System.Drawing.Font f = new System.Drawing.Font("Arial", 16f,
FontStyle.Regular);
font = new Microsoft.DirectX.Direct3D.Font(device, f);
11
}
private void LoadTexture()
{
texture = TextureLoader.FromFile(device,"E:\\TYCS\\images\\img1.jpg",400, 400,
1, 0,
Format.A8B8G8R8, Pool.Managed, Filter.Point, Filter.Point,
Color.Transparent.ToArgb());
}
private void InitDevice()
{
PresentParameterspp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing, pp);
}
private void Render()
{
device.Clear(ClearFlags.Target, Color.CornflowerBlue, 0, 1);
device.BeginScene();
using (Sprite s = new Sprite(device))
{
s.Begin(SpriteFlags.AlphaBlend);
s.Draw2D(texture, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0,
device.Viewport.Width, device.Viewport.Height), new Point(0, 0), 0f, new
Point(0, 0), Color.White);
font.DrawText(s, "Model College", new Point(0, 0), Color.Black);
s.End();
12
}
device.EndScene();
device.Present();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
Output:
5. PROGRAM 5
PROCEDURE TO CREATE AN ANIMATION TO REPRESENT THE GROWING MOON.
1. Open flash 8 software -> click on flash document->go to windows->properties
->select the propertiestool-> choose the Background to black.
2. Go to fill color under tool bar-> select the white color.
3. Select the oval tool in order to draw the moon. u will get a white circle.
4. Select the oval tool in order to draw the moon. u will get a white circle.
5. Select the white circle on the worksheet using the selection tool->right click-
>convert to symbol->select movie clip->give suitable name eg: moon->click ok.
6. Go to filter->click on the + symbol->select glow to apply glowing effect-> select the
color to white under glow and adjust the blur x/blur y values.
7. Click on the + symbol again and chose blur-> again adjust the blur x/blur y values.
8. Place the moon where ever you want on the work area.double click on layer 1 and
rename as MOON.
9. Insert another layer->rename it as Animation.
10. Select the fill color to black-> select oval tool and draw a circle on the moon to cover
the moon->select the newly added circle-> right click-> convert to symbol-> movie
clip-> name it as Animation.
13
11. Go to filter-> select + symbol->give the glow and blur effect as did for moon.
12. Select the 150th frame in moon layer->right click->insert key frame.
repeat the same for Animation layer.
13. Click on the 149th keyframe of animation layer ->right click->press create motion->
select the animation movie clip and move slowly across the moon.
14. Finally go to control-> test movie-> u will get a growing moon as the
Output:
14
6. PROGRAM 6:
PROCEDURE TO CREATE AN ANIMATION TO INDICATE A BALL BOUNCING ON
STEPS.
1. Go to start- macromedia- click on flash document
2. select the line tool and draw the steps. colour it using the paint bucket tool
3. Select the circle from the tool bar and create a circle on the work area.
4. Now fill the colour to the circle using the paint bucket tool from the tool bar.
5. Go to frames right click on the first frame and choose insert key frame.
slightly move the ball. Repeat the same procedure by adding new key frames
to show the ball change the shape of the ball slightly when it touches the
15
surface.
6. In order to change the shape use the free transform tool.
7. Go to control and click on test movies .you will observe the ball bouncing on steps
Output:
7. PROGRAM 7
PROCEDURE TO SIMULATE MOVEMENT OF A CLOUD.
1. go to start- macromedia- click on flash document
2. create a blue background in layer 1
3. Now insert a layer 2 and draw the clouds in this layer.
4. in order to create the clouds, go to tool bar and select pencil option,
draw the cloud
in layer2
5. fill the colour to the cloud, right click on it- choose convert to symbol
option- give
the name as cloud
16
6. select the movie clip option and click ok.
7. Go to filter->click on the + symbol->select glow to apply glowing
effect-> select the
colour to white
8. under glow and adjust the blur x/blur y values.
9. give the appropriate blur effect to the cloud.
10. go to frames, insert key frame on both the layer, create the motion
tween on 2
nd
layer and move the clouds
11. finally go to control->click on test movies.
Output:
17
8. PROGRAM 8
PROCEDURE TO DRAW THE FAN BLADES AND TO GIVE
PROPER ANIMATION.
1. go to start-> macromedia-> click on flash document
2. Create a background on layer 1.
3. Insert another layer-> draw only fan blades and its circle.
4. Insert another layer and draw fan stand.
5. On each layer right click on frames and insert key frames.
6. Select the fan blade’s layer and insert new key frame-> select the fan
blades by free transform
tool and rotate the circle a little bit.
7. repeat the rotation until you get the fan rotation animation
8. Go to control->test movie to see the animation.
Output:
18
9. PROGRAM - 9
PROCEDURE TO SIMULATE A BALL HITTING ANOTHER BALL.
1. Go to start->Macro Media-click on Flash document.
2. choose the circle option displayed in the toolbar. create two circle at
the opposite ends.
3.go to frames-> right click on the 1
st blank frame and click insert key frames.
4. Select the 1
st ball and make it to move towardsthe other till it touches.
5. Change the shape of the ball using free transform tool as soon as the
two ball touches
each other. after hitting each other make them to move towards opposite
direction.
6. before moving to the opposite direction bring back the ballsto its
originalshapes.
7. finally test the animation by selecting control->movie clip.
Output:
19
10. PROGRAM 10
PROCEDURE TO CHANGE A CIRCLE INTO A SQURE USING FLASH.
1. Go to start->macromedia->flash document
2. Select the circle tool from the tool bar. draw a circle on the work area.colour it
3. Click on the 40th key frame-> insert new key frame.
4. Selecting the last key frame->draw a rectangle on the circle by selecting the
rectangle tool bar so that it will cover the circle. colour the rectangle by the
different colour.
5. Again click on the last frame->under properties->under tween->change the
option shape
from none.
20
6. Then again select the last but one frame->go to properties->tween->change to
shape.
7. Go to control->test movie->see the circle changing in to rectangle.
Output:
21