GP Prac 2
GP Prac 2
GP Prac 2
Code: -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;
namespace Practical_1
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
public void InitDevice()
{
PresentParameters pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing, pp);
}
public void Render()
{
device.Clear(ClearFlags.Target, Color.Orange, 0, 1);
device.Present();
}
1 SIGNATURE:____________________
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
O/P: -
2 SIGNATURE:____________________
Date: -21/07/22
Practical 2: - Draw triangle using Direct3D 11
Code: -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;
using System.Windows.Forms;
namespace Practical2
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
O/P: -
4 SIGNATURE:____________________
Date: -28/07/22
namespace Practical_3
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
private CustomVertex.PositionTextured[] vertex = new
CustomVertex.PositionTextured[3];
private Texture texture;
public Form1()
{
InitializeComponent();
InitDevice();
}
5 SIGNATURE:____________________
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("C:\\Users\\Admin\\Downloads\\Wallpapers\\4.jpg"), 0,
Pool.Managed);
}
6 SIGNATURE:____________________
7 SIGNATURE:____________________
Date: -25/08/22
namespace Practical_4
{
public partial class Form1 : Form
{
private Microsoft.DirectX.Direct3D.Device device;
private CustomVertex.PositionNormalColored[] vertex = new
CustomVertex.PositionNormalColored[3];
public Form1()
{
InitializeComponent();
InitDevice();
}
device.RenderState.Lighting = true;
device.Present();
}
O/P: -
9 SIGNATURE:____________________
10 SIGNATURE:____________________
Date: -25/08/22
Practical 5: - Specular Lightning (Programmable Spot Lightning
using Direct3D 11)
Code: -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using
System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace Practical_5
{
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();
}
11 SIGNATURE:____________________
System.Drawing.Font f = new System.Drawing.Font("Arial", 16f,
FontStyle.Regular);
font = new Microsoft.DirectX.Direct3D.Font(device, f);
}
14 SIGNATURE:____________________
private void OnTriggerEnter2D(Collider2D collision) {
collision.gameObject.SetActive(false);
coins++;
coinText.text = "Coins:" + coins.ToString();
}
}
O/P: -
15 SIGNATURE:____________________
Date: -15/09/22
Practical 7: - Coin collator game in Unity
Code: -
CoinController.cs:
using UnityEngine;
public class CoinController : MonoBehaviour
{ private void Update() {
transform.Rotate(new Vector3(0, 20, 0));
}
private void OnTriggerEnter(Collider other)
{ gameObject.SetActive(false);
}
}
SphereController.cs:
using UnityEngine;
public class SphereController : MonoBehaviour
{ Rigidbody rigidbody;
public float speed = 150;
void Start() {
rigidbody = GetComponent<Rigidbody>();
}
void FixedUpdate() {
if (Input.GetKey(KeyCode.UpArrow)) {
rigidbody.AddForce(Vector3.forward *
16 SIGNATURE:____________________
Time.fixedDeltaTime * speed);
}
if (Input.GetKey(KeyCode.DownArrow))
{ rigidbody.AddForce(Vector3.back *
Time.fixedDeltaTime * speed);
}
if (Input.GetKey(KeyCode.LeftArrow)) {
rigidbody.AddForce(Vector3.left *
Time.fixedDeltaTime * speed);
}
if (Input.GetKey(KeyCode.RightArrow)) {
rigidbody.AddForce(Vector3.right *
Time.fixedDeltaTime * speed);
}
}
}
O/P: -
17 SIGNATURE:____________________
18 SIGNATURE:____________________
Date: -22/09/22
Practical 8: - Break the wall game in Unity
Code: -
RotateCube.cs:
using UnityEngine;
public class CoinController : MonoBehaviour
{ private void Update() {
transform.Rotate(new Vector3(0, 20, 0));
}
}
SphereController.cs:
using UnityEngine;
public class SphereController : MonoBehaviour
{ Rigidbody rigidbody;
public float speed = 150;
void Start() {
rigidbody = GetComponent<Rigidbody>();
}
void FixedUpdate() {
if (Input.GetKey(KeyCode.UpArrow)) {
rigidbody.AddForce(Vector3.forward *
Time.fixedDeltaTime * speed);
}
if (Input.GetKey(KeyCode.DownArrow)) {
rigidbody.AddForce(Vector3.back *
19 SIGNATURE:____________________
Time.fixedDeltaTime * speed);
}
if (Input.GetKey(KeyCode.LeftArrow)) {
rigidbody.AddForce(Vector3.left *
Time.fixedDeltaTime * speed);
}
if (Input.GetKey(KeyCode.RightArrow)) {
rigidbody.AddForce(Vector3.right *
Time.fixedDeltaTime * speed);
}
}
}
O/P: -
20 SIGNATURE:____________________
21 SIGNATURE:____________________
22 SIGNATURE:____________________