From 58fd73629a1051eaa2502c3cb1ebeda76fd7843e Mon Sep 17 00:00:00 2001
From: sr1g19 <sr1g19@soton.ac.uk>
Date: Tue, 11 May 2021 04:17:28 +0000
Subject: [PATCH] Upload New File

---
 src/main.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)
 create mode 100644 src/main.c

diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..204751a
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,141 @@
+/* COMP2215: Task 02---MODEL ANSWER */
+/* For La Fortuna board.            */
+
+
+#include <avr/io.h>
+#include <stdio.h>
+#include <util/delay.h>
+#include "lcd.h"
+#include "rasterize.h"
+#include "img.h"
+
+
+#define BUFFSIZE 256
+
+void init(void);
+void rotationExample(float angle);
+void scaleExample(float xScale, float yScale);
+void pogExample(float angle, float xScale, float yScale);
+void perspectiveExample();
+void compositeExample();
+void compositeExample2();
+
+void main(void) {
+    init();
+    rotationExample(M_2_PI/2 + 0.05);
+    _delay_ms(3000);
+    scaleExample(3.36, 3.9);
+    _delay_ms(3000);
+    pogExample(M_2_PI/2 + 0.05, 2.2, 2.2);
+    _delay_ms(3000);
+    perspectiveExample();
+    _delay_ms(3000);
+    compositeExample();
+    _delay_ms(3000);
+    compositeExample2();
+}
+rectangle imgReg = {0,63,0,63};
+
+void rotationExample(float angle) {
+    clear_screen();
+    _2x2Matrix m = {cos(angle),-sin(angle), sin(angle), cos(angle)};
+    rect2d rect = {{0,0}, {63,0}, {63,63},{0,63}};
+    affineRasterize(m, testTile, imgReg, 10, 10);
+}
+
+void scaleExample(float xScale, float yScale) {
+    clear_screen();
+    _2x2Matrix m = {xScale,0, 0, yScale};
+    rect2d rect = {{0,0}, {63,0}, {63,63},{0,63}};
+    affineRasterize(m, testTile, imgReg, 10, 10);
+}
+void pogExample(float angle, float xScale, float yScale){
+    clear_screen();
+    _2x2Matrix m1 = {cos(angle),-sin(angle), sin(angle), cos(angle)};
+    _2x2Matrix m2 = {xScale,0, 0, yScale};
+    _2x2Matrix m = multiply_2x2(m1, m2);
+    rect2d rect = {{0,0}, {63,0}, {63,63},{0,63}};
+    affineRasterize(m, testTile, imgReg, 30, 30);
+}
+void perspectiveExample() {
+    clear_screen();
+    tri2d tuv = {{0,0}, {63,0},{0,63}};
+    tri3d t = {{20,10, 1}, {303,103,1},{43,200, 1}};
+    perspectiveRasterizeComposite(t, tuv, testTile, imgReg,1);
+}
+void compositeExample() {
+    clear_screen();
+    for(int y = 0; y < LCDWIDTH- 15; y+=16){
+        for(int x = 0; x < LCDHEIGHT - 15; x+=16){
+            rectangle r = {0+x,15+x,0+y,15+y};
+            fill_rectangle_indexed_MEM(r, grassTile);
+        }
+    }
+    rectangle waterReg = {0,waterImgWidth-1,0,waterImgHeight-1};
+
+    tri2d tuv1 = {{0,0}, {62,0},{0,16}};
+    tri2d tuv2 = {{62,0},{0,16}, {62,16}};
+    tri3d t1 = {{60,180, 1}, {LCDHEIGHT-60,180,1},{20,180+50, 1}};
+    tri3d t2 = {{LCDHEIGHT-60,180,1},{20,180+50, 1},{LCDHEIGHT-20,180+50,1}};
+    perspectiveRasterizeComposite(t1, tuv1, waterImg, waterReg,0.3);
+    perspectiveRasterizeComposite(t2, tuv2, waterImg, waterReg,0.3);
+
+    rectangle marshReg = {0,marshImgWidth-1,0,marshImgHeight-1};
+
+    tri2d tuv3 = {{0,0}, {50,0}, {0,52.5}};
+    tri2d tuv4 = {{50,0}, {0,52.5}, {50,52.5}};
+    tri3d t3 = {{50,70,1},{LCDHEIGHT-50,70,1},{80,200,1}};
+    tri3d t4 = {{LCDHEIGHT-50,70,1},{80,200,1},{LCDHEIGHT-80,200,1}};
+    perspectiveRasterizeComposite(t4, tuv4, marshImg, marshReg,1);
+    perspectiveRasterizeComposite(t3, tuv3, marshImg, marshReg,1);
+}
+
+void compositeExample2() {
+    clear_screen();
+    rectangle imgReg = {0,15.9,0,15.9};
+    tri2d tuv1 = {{0,0}, {15.9,0},{15.9,15.9}};
+    tri2d tuv2 = {{0,0},{0,15.9}, {15.9,15.9}};
+    tri2d tuv3 = {{0,0}, {15.9,15.9}, {0,15.9}};
+    tri2d tuv4 = {{0,0}, {15.9,15.9}, {15.9,0}};
+    tri2d tuv5 = { {0,0}, {15.9,10.6}, {15.9,15.9}};
+
+    _3x1Matrix p0 = {60,40,1};
+    _3x1Matrix p1 = {160,0,1};
+    _3x1Matrix p2 = {260,40,1};
+    _3x1Matrix p3 = { 260, 160, 1};
+    _3x1Matrix p4 = {160,200, 1};
+    _3x1Matrix p5 = { 60, 160, 1};
+    _3x1Matrix p6 = {160,80,1};
+    _3x1Matrix p7 = {160,120,1};
+
+    tri3d c1t1 = {p0,p1,p2};
+    tri3d c1t2 = {p0,p6,p2};
+    perspectiveRasterizeComposite(c1t1, tuv1, woodTile, imgReg,1);
+    perspectiveRasterizeComposite(c1t2, tuv2, woodTile, imgReg,1);
+
+    tri3d c2t1 = {p4,p6,p2};
+    tri3d c2t2 = {p4,p3,p2};
+    perspectiveRasterizeComposite(c2t1, tuv1, woodTile, imgReg,1);
+    perspectiveRasterizeComposite(c2t2, tuv2, woodTile, imgReg,1);
+
+    tri3d c3t1 = {p0,p7,p5};
+    tri3d c3t2 = {p0,p6,p7};
+    perspectiveRasterizeComposite(c3t1, tuv3, darkWoodTile, imgReg,1);
+    perspectiveRasterizeComposite(c3t2, tuv5, darkWoodTile, imgReg,1);
+
+    tri3d c4t1 = {p5,p7,p4};
+    perspectiveRasterizeComposite(c4t1, tuv4, darkWoodTile, imgReg,1);
+
+    tri3d c5t1 = {p5,p0,p6};
+    tri3d c5t2 = {p5,p4,p6};
+    perspectiveRasterizeComposite(c5t1, tuv1, glassTile, imgReg,0.4);
+    perspectiveRasterizeComposite(c5t2, tuv2, glassTile, imgReg,0.4);
+}
+
+void init(void) {
+    /* 8MHz clock, no prescaling (DS, p. 48) */
+    CLKPR = (1 << CLKPCE);
+    CLKPR = 0;
+
+    init_lcd();
+}
-- 
GitLab