Professional Documents
Culture Documents
GP Journal-2 (Itscholar - Codegency.co - In)
GP Journal-2 (Itscholar - Codegency.co - In)
Practical 1
Code:
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
using System.Windows.Forms;
namespace DxPrac1 {
public partial class Form1 : Form {
Device d;
public Form1() {
InitializeComponent();
InitDevice();
}
void InitDevice() {
PresentParameters presentParameters = new
PresentParameters();
presentParameters.Windowed = true;
presentParameters.SwapEffect =
SwapEffect.Discard;
d = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing,
presentParameters);
}
void Render() {
CustomVertex.TransformedColored[] vertex = new
CustomVertex.TransformedColored[3];
vertex[0].Position = new Vector4(200, 75, 0,
0);
vertex[0].Color = Color.Red.ToArgb();
vertex[1].Position = new Vector4(300, 250, 0,
0);
vertex[1].Color = Color.Green.ToArgb();
vertex[2].Position = new Vector4(100, 250, 0,
0);
vertex[2].Color = Color.Blue.ToArgb();
d.Clear(ClearFlags.Target, Color.White, 0, 1);
d.BeginScene();
d.VertexFormat =
CustomVertex.TransformedColored.Format;
d.DrawUserPrimitives(PrimitiveType.TriangleList
, 1, vertex);
d.EndScene();
d.Present();
}
Game Programmig Journal
Output:
Game Programmig Journal
Practical 2
Code:
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
using System.Windows.Forms;
namespace DxPrac1 {
public partial class Form1 : Form {
Device d;
public Form1() {
InitializeComponent();
InitDevice();
}
void InitDevice() {
PresentParameters presentParameters = new
PresentParameters();
presentParameters.Windowed = true;
presentParameters.SwapEffect =
SwapEffect.Discard;
d = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing,
presentParameters);
}
void Render() {
CustomVertex.TransformedColored[] vertex = new
CustomVertex.TransformedColored[6];
vertex[0].Position = vertex[5].Position = new
Vector4(200, 100, 0, 0);
vertex[1].Position = new Vector4(300, 100, 0,
0);
vertex[2].Position = vertex[3].Position = new
Vector4(300, 300, 0, 0);
vertex[4].Position = new Vector4(200, 300, 0,
0);
d.Clear(ClearFlags.Target, Color.White, 0, 1);
d.BeginScene();
d.VertexFormat =
CustomVertex.TransformedColored.Format;
d.DrawUserPrimitives(PrimitiveType.TriangleList
, 2, vertex);
d.EndScene();
d.Present();
}
Game Programmig Journal
Output:
Game Programmig Journal
Practical 3
Code:
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
using System.Windows.Forms;
using static Microsoft.DirectX.Direct3D.CustomVertex;
namespace DxPrac1 {
public partial class Form1 : Form {
Device d;
Texture texture;
public Form1() {
InitializeComponent();
}
void InitDevice() {
PresentParameters presentParameters = new
PresentParameters();
presentParameters.Windowed = true;
presentParameters.SwapEffect =
SwapEffect.Discard;
d = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing,
presentParameters);
d.Transform.Projection =
Matrix.PerspectiveFovLH(3.14f / 4,
d.Viewport.Width / d.Viewport.Height, 1, 1000);
d.Transform.View = Matrix.LookAtLH(new
Vector3(0, 0, 6), new Vector3(), new Vector3(0,
1, 0));
d.RenderState.Lighting = false;
texture = new Texture(d, new
Bitmap("C:\\Users\\minba\\Downloads\\texture.pn
g"), 0, Pool.Managed);
}
void Render() {
PositionTextured[] vertex = new
PositionTextured[6];
vertex[0] = vertex[5] = new
PositionTextured(new Vector3(0, 2, 1), 1, 1);
vertex[1] = new PositionTextured(new Vector3(0,
-2, 1), 1, 0);
vertex[2] = vertex[3] = new
PositionTextured(new Vector3(2, -2, 1), 0, 0);
vertex[4] = new PositionTextured(new Vector3(2,
2, 1), 0, 1);
d.Clear(ClearFlags.Target, Color.White, 1, 0);
d.BeginScene();
d.VertexFormat = PositionTextured.Format;
Game Programmig Journal
d.SetTexture(0,texture);
d.DrawUserPrimitives(PrimitiveType.TriangleList
, 2, vertex);
d.EndScene();
d.Present();
}
private void Form1_Paint(object sender,
PaintEventArgs e) {
Render();
}
private void Form1_Load(object sender,
System.EventArgs e) {
InitDevice();
}
}
}
Output:
Game Programmig Journal
Practical 4
Code:
using Microsoft.DirectX.Direct3D;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DxPrac1 {
public partial class Form1 : Form {
private Microsoft.DirectX.Direct3D.Device device;
private Microsoft.DirectX.Direct3D.Texture texture;
private Microsoft.DirectX.Direct3D.Font font;
public Form1() {
InitializeComponent();
InitDevice();
InitFont();
LoadTexture();
}
Output:
Game Programmig Journal
Practical 5
Code:
PlayerController.cs
using UnityEngine;
using UnityEngine.UI;
Rigidbody2D rigidbody;
int coins = 0;
public Text coinText;
void Start() {
rigidbody = GetComponent<Rigidbody2D>();
}
void Update() {
if (Input.GetKey(KeyCode.UpArrow)) {
rigidbody.AddForce(Vector2.up);
}
if (Input.GetKey(KeyCode.DownArrow)) {
rigidbody.AddForce(Vector2.down);
}
if (Input.GetKey(KeyCode.LeftArrow)) {
rigidbody.AddForce(Vector2.left);
}
if (Input.GetKey(KeyCode.RightArrow)) {
rigidbody.AddForce(Vector2.right);
}
}
private void OnTriggerEnter2D(Collider2D collision) {
collision.gameObject.SetActive(false);
coins++;
coinText.text = "Coins:" + coins.ToString();
}
}
Game Programmig Journal
Output:
Game Programmig Journal
Practical 6
Code:
CoinController.cs
using UnityEngine;
SphereController.cs
using UnityEngine;
}
}
Game Programmig Journal
Ouptut:
Game Programmig Journal
Practical 7
Code:
RotateCube.cs
using UnityEngine;
Output:
Game Programmig Journal
Practical 8
Output: