Professional Documents
Culture Documents
GRAFIKA KOMPUTER
NRP : 2110181033
#include <GL/glut.h>
#include <math.h>
typedef struct {
float x;
float y;
float z;
} Point3D_t;
typedef struct {
float m[3][3];
} Matrix3D_t;
typedef struct {
float v[3];
} Vector3D_t;
typedef struct {
float r;
float g;
float b;
} Color_t;
Point3D_t bintangZoom[10] = {
{0,90}, {19,34}, {77,34}, {30,-1}, {48,-55},
{0,-22}, {-48,-55}, {-26,-1}, {-77,34}, {-17,34}
CHANDRA KIRANA J 1
[Segitiga dan Bintang Bergerak]
};
Point3D_t segitigaRotasi[3] = {
{-100,0},{0,200},{100,0}
};
void sumbuKoordinat() {
Point3D_t sumbuX[2] = { {-320,0},{320,0} };
Point3D_t sumbuY[2] = { {0,-240},{0,240} };
Color_t col = { 0,0,1 };
drawLine(sumbuX, 2, col);
drawLine(sumbuY, 2, col);
}
void display(void) {
CHANDRA KIRANA J 2
[Segitiga dan Bintang Bergerak]
glClear(GL_COLOR_BUFFER_BIT);
sumbuKoordinat();
//Bintang_Rotasi();
//Bintang_Scale();
//Segitiga_Rotasi();
//Segitiga_Rotasi2();
//Segitiga_Vertical();
Segitiga_Horizontal();
glutSwapBuffers();
}
void initialize(void) {
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutCreateWindow("2110181033_Chandra Kirana_Segita dan Bintang Bergerak");
glClearColor(1, 1, 1, 0);
gluOrtho2D(-320, 320, -240, 240);
}
void Bintang_Rotasi() {
Color_t color = { 1,0,0 };
matrix3DZ = rotationZ(sudut);
drawPolygon(bintangRotasi, 10, color);
for (size_t i = 0; i < 10; i++)
{
vec3D = point2Vector3d(bintangRotasi[i]);
vec3D = operator*(matrix3DZ, vec3D);
bintangRotasi[i] = vector2Point3d(vec3D);
}
}
void Bintang_Scale() {
Color_t color = { 1,0,0 };
matrix3DZ = scalingZ(1.05);
drawPolygon(bintangZoom, 10, color);
for (size_t i = 0; i < 10; i++)
{
CHANDRA KIRANA J 3
[Segitiga dan Bintang Bergerak]
vec3D = point2Vector3d(bintangZoom[i]);
vec3D = operator*(matrix3DZ, vec3D);
bintangZoom[i] = vector2Point3d(vec3D);
}
}
void Segitiga_Rotasi() {
Color_t color = { 1,0,0 };
matrix3DZ = rotationZ(sudut);
drawFillPolygon(segitigaRotasi, 3, color);
for (size_t i = 0; i < 3; i++)
{
vec3D = point2Vector3d(segitigaRotasi[i]);
vec3D = operator*(matrix3DZ, vec3D);
segitigaRotasi[i] = vector2Point3d(vec3D);
}
}
void Segitiga_Rotasi2() {
Color_t color = { 1,0,0 };
matrix3DZ = rotationZ(sudut);
drawFillPolygon(segitiga01, 3, color);
drawFillPolygon(segitiga02, 3, color);
drawFillPolygon(segitiga03, 3, color);
drawFillPolygon(segitiga04, 3, color);
for (size_t i = 0; i < 3; i++)
{
vec3D = point2Vector3d(segitiga01[i]);
vec3D = operator*(matrix3DZ, vec3D);
segitiga01[i] = vector2Point3d(vec3D);
vec3D = point2Vector3d(segitiga02[i]);
vec3D = operator*(matrix3DZ, vec3D);
segitiga02[i] = vector2Point3d(vec3D);
vec3D = point2Vector3d(segitiga03[i]);
vec3D = operator*(matrix3DZ, vec3D);
segitiga03[i] = vector2Point3d(vec3D);
vec3D = point2Vector3d(segitiga04[i]);
vec3D = operator*(matrix3DZ, vec3D);
segitiga04[i] = vector2Point3d(vec3D);
}
}
void Segitiga_Vertical() {
Color_t color = { 1,0,0 };
drawFillPolygon(segitigaV1, 3, color);
drawFillPolygon(segitigaV2, 3, color);
drawFillPolygon(segitigaV3, 3, color);
drawFillPolygon(segitigaV4, 3, color);
drawFillPolygon(segitigaV5, 3, color);
drawFillPolygon(segitigaV6, 3, color);
for (size_t i = 0; i < 3; i++)
{
segitigaV1[i].y += 2;
segitigaV2[i].y += 2;
segitigaV3[i].y += 2;
segitigaV4[i].y += 2;
segitigaV5[i].y += 2;
CHANDRA KIRANA J 4
[Segitiga dan Bintang Bergerak]
segitigaV6[i].y += 2;
}
}
void Segitiga_Horizontal() {
Color_t color = { 1,0,0 };
drawFillPolygon(segitigaH1, 3, color);
drawFillPolygon(segitigaH2, 3, color);
drawFillPolygon(segitigaH3, 3, color);
drawFillPolygon(segitigaH4, 3, color);
drawFillPolygon(segitigaH5, 3, color);
drawFillPolygon(segitigaH6, 3, color);
for (size_t i = 0; i < 3; i++)
{
segitigaH1[i].x += 2;
segitigaH2[i].x += 2;
segitigaH3[i].x += 2;
segitigaH4[i].x += 2;
segitigaH5[i].x += 2;
segitigaH6[i].x += 2;
}
}
Matrix3D_t createIdentity() {
Matrix3D_t a;
for (size_t i = 0; i < 3; i++) {
for (size_t j = 0; j < 3; j++)
a.m[i][j] = 0;
a.m[i][i] = 1;
} return a;
}
Matrix3D_t scalingZ(float m) {
Matrix3D_t u = createIdentity();
u.m[1][1] = m;
u.m[0][0] = m;
return u;
}
CHANDRA KIRANA J 5
[Segitiga dan Bintang Bergerak]
Point3D_t pnt;
pnt.x = vector.v[0];
pnt.y = vector.v[1];
pnt.z = vector.v[2];
return pnt;
}
2. Bintang Rotasi
Source Code
void Bintang_Rotasi() {
Color_t color = { 1,0,0 };
matrix3DZ = rotationZ(sudut);
drawPolygon(bintangRotasi, 10, color);
for (size_t i = 0; i < 10; i++)
{
vec3D = point2Vector3d(bintangRotasi[i]);
vec3D = operator*(matrix3DZ, vec3D);
bintangRotasi[i] = vector2Point3d(vec3D);
}
}
CHANDRA KIRANA J 6
[Segitiga dan Bintang Bergerak]
Capture
3. Bintang Scale
Source Code
void Bintang_Scale() {
Color_t color = { 1,0,0 };
matrix3DZ = scalingZ(1.05);
drawPolygon(bintangZoom, 10, color);
for (size_t i = 0; i < 10; i++)
{
vec3D = point2Vector3d(bintangZoom[i]);
vec3D = operator*(matrix3DZ, vec3D);
bintangZoom[i] = vector2Point3d(vec3D);
}
}
CHANDRA KIRANA J 7
[Segitiga dan Bintang Bergerak]
Output
4. Segitiga Rotasi
Source Code
void Segitiga_Rotasi() {
Color_t color = { 1,0,0 };
matrix3DZ = rotationZ(sudut);
drawFillPolygon(segitigaRotasi, 3, color);
for (size_t i = 0; i < 3; i++)
{
vec3D = point2Vector3d(segitigaRotasi[i]);
vec3D = operator*(matrix3DZ, vec3D);
segitigaRotasi[i] = vector2Point3d(vec3D);
}
}
CHANDRA KIRANA J 8
[Segitiga dan Bintang Bergerak]
Output
void Segitiga_Rotasi2() {
Color_t color = { 1,0,0 };
matrix3DZ = rotationZ(sudut);
drawFillPolygon(segitiga01, 3, color);
drawFillPolygon(segitiga02, 3, color);
drawFillPolygon(segitiga03, 3, color);
drawFillPolygon(segitiga04, 3, color);
for (size_t i = 0; i < 3; i++)
{
vec3D = point2Vector3d(segitiga01[i]);
vec3D = operator*(matrix3DZ, vec3D);
segitiga01[i] = vector2Point3d(vec3D);
vec3D = point2Vector3d(segitiga02[i]);
CHANDRA KIRANA J 9
[Segitiga dan Bintang Bergerak]
Output
CHANDRA KIRANA J 10
[Segitiga dan Bintang Bergerak]
6. Segitiga Vertical
Source Code
void Segitiga_Vertical() {
Color_t color = { 1,0,0 };
drawFillPolygon(segitigaV1, 3, color);
drawFillPolygon(segitigaV2, 3, color);
drawFillPolygon(segitigaV3, 3, color);
drawFillPolygon(segitigaV4, 3, color);
drawFillPolygon(segitigaV5, 3, color);
drawFillPolygon(segitigaV6, 3, color);
for (size_t i = 0; i < 3; i++)
{
segitigaV1[i].y += 2;
segitigaV2[i].y += 2;
segitigaV3[i].y += 2;
segitigaV4[i].y += 2;
segitigaV5[i].y += 2;
segitigaV6[i].y += 2;
}
}
Output
CHANDRA KIRANA J 11
[Segitiga dan Bintang Bergerak]
7. Segitiga Horizontal
Source Code
void Segitiga_Horizontal() {
Color_t color = { 1,0,0 };
drawFillPolygon(segitigaH1, 3, color);
drawFillPolygon(segitigaH2, 3, color);
drawFillPolygon(segitigaH3, 3, color);
drawFillPolygon(segitigaH4, 3, color);
drawFillPolygon(segitigaH5, 3, color);
drawFillPolygon(segitigaH6, 3, color);
for (size_t i = 0; i < 3; i++)
{
segitigaH1[i].x += 2;
segitigaH2[i].x += 2;
segitigaH3[i].x += 2;
segitigaH4[i].x += 2;
segitigaH5[i].x += 2;
segitigaH6[i].x += 2;
CHANDRA KIRANA J 12
[Segitiga dan Bintang Bergerak]
}
}
Output
CHANDRA KIRANA J 13