Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rasterisation Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sr1g19
Rasterisation Project
Commits
58fd7362
Commit
58fd7362
authored
4 years ago
by
sr1g19
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
f847af5e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.c
+141
-0
141 additions, 0 deletions
src/main.c
with
141 additions
and
0 deletions
src/main.c
0 → 100644
+
141
−
0
View file @
58fd7362
/* 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
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment