Hi, i found this code from an article, i want to compile this code, buat I don't have file polygon.h. Can you send file polygon.h to me, because i have search from any web buat i don't find it.
This the code
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<math.h>
#include<stdlib.h>
#include<GL/glut.h>
#define SCREEN_W 800
#define SCREEN_H 600
#define MAX_INPUT 20
#define MAX_POLYGON 10
#define MAX_SINAR 150
#define BELUM_MEMBUAT_POLYGON -1
#define MEMBUAT_POLYGON 1
#define SIAP_BUAT_POLYGON 0
#define SELESAI_BUAT_POLUGON 2
#define KLIK_TITIK_P1 3
#define CARI_SINAR 4
#include"vector.h"
#include"polygon.h"
int status = SIAP_BUAT_POLYGON;
Poly polygon[MAX_POLYGON];
int jumlahPolygon = 0;
int jumlahSinar = 0;
vector p,p1;
vector sinar[MAX_SINAR];
int hitTime[MAX_POLYGON];
vector currentSinar;
int lokasiPantul[2];
void printPolygon()
{
// membuat garis loop / buat polygon
glColor3f(0.0f, 0.0f, 0.0f);
for (int 1=0; i<jumlahPolygon; i++)
{
glBegin(GL_LINE_LOOP);
for (int j=0; j<polygon[i].getJumlahInput(); j++)
{
glVertex2d(polygon[i].get(j).getX(), polygon[i].get(j).getY());
}
glEnd();
}
glFlush();
}
void printPoint()
{
// buat titik
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_POINTS);
for (int i=0; i<jumlahPolygon; i++)
{
for (int j=0; j<polygon[i].getJumlahInput(); j++)
{
glVertex2d(polygon[i].get(j).getX(), polygon[i].get(j).getY());
}
}
glColor3f(1, 0.0f, 1);
glVertex2d(p.getX(), p.getY());
glEnd();
glflush();
}
void printSinar()
{
glColor3f(1, 0.0f, 1);
glBegin(GL_LINES);
for (int i=1; i<jumlahSinar; i++)
{
glBegin(GL_LINES);
glVertex2d(sinar[i-1].getX(), sinar[i-1].getY());
glVertex2d(sinar[i].getX(), sinar[i].getY());
glEnd();
}
glFlush();
}
double cariUa(vector VR, vector titikAwal, vector titikTembok1, vector titikTembok2)
{
vektor titikToTembok;
vector tembok;
titikToTembok.set(titikTembok1.getX()-titikAwal.getX(), titikTembok1.getY()-titikAwal.getY(),0);
tembok.set(titikTembok2.getX()-titikTembok1.getX(), titikTembok2.getY()-titikTembok1.getY(),0);
vector V;
double Ua=V.crossProduct(VR, titikToTembok).getZ()/V.crossProduct(tembok,VR).getZ();
return Ua;
}
double getHitTime(vector VR, vector titikAwal, vector titikTembok1, vector titikTembok2)
{
vector titikToTembok;
vector Tembok;
titikToTembok.set(titikTembok1.getX()-titikAwal.getX(), titikTembok1.getY()-titikAwal.getY(),0);
tembok.set(titikTembok2.getX()-titikTembok1.getX(), titikTembok2.getY()-titikTembok1.getY(),0);
Vector V;
double Ua=V.crossProduct(tembok, titikToTembok).getZ()/V.crossProduct(tembok,VR).getZ();
return hitTime;
}
vector getTitikPantul(vector tembok, vector sinar, double hitTime)
{
vector pantul;
pantul.set(tembok.getX()+hitTime*sinar.getX(), tembok.getY()+hitTime*sinar.getT(),0);
return pantul;
}
vector getVectorPantul(vector sinar, vector normal)
{
vector pantul;
vector V;
double dotProductX2=2*V.dotProduct(sinar,normal);
pantul.set(sinar.getX()-dotProductX2*normal.getX(), sinar.getY()-dotProductX2*normal.getY());
return pantul;
}
vector getSinar()
{
// cari tembok yang menabrak dan cari hitTimenya
double Ua;
double minHitTime = -1;
int lokasiTembok [2];
for (int i=0; i<julahPolygon; i++)
{
for (int j=0; j<polygon[i].getJumlahInput(); j++)
{
if (i==lokasiPantul[0] && j++lokasiPantul[1])continue;
Ua = cariUa(currentSinar, sinar[jumlahSinar-1], polygon[i].get(j), polygon[i].get((j+1)%polygon[i].getJumlahInput()));
if (Ua>0 && Ua<=1)
{
// cari hitTime
double hitTime=getHitTime(currentSinar,sinar[jumlahSinar-1],polygon[i].get(j), polygon[i].get((j+1)%polygon[i].getJumlahInput()));
// jika bertabrakan
if (hitTime>0)
{
if (minHitTime==-1)
{
minHitTime=hitTime;
lokasiTembok[0]=i;
lokasiTembok[1]=j;
}
else if (hitTime < minHitTime)
{
minHitTime=hitTime;
lokasiTembok[0]=i;
lokasiTembok[1]=j;
}
}
}
}
}
lokasiPantul[0]=lokasiTembok[0];
lokasiPantul[1]=lokasiTembok[1];
printf("tembok pantulan : %d,%d\n",lokasiTembok[0],lokasiTembok[1]);
// tembok yang kena
vector tembok = polygon[lokasiTembok[0]].getLine(lokasiTembok[1]);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** cari titik pantul */
vektor titikPantul = getTitikPantul(sinar[jumlahSinar-1),currentSinar,minHitTime);
printf(Titik pantul=%3lf,%3lf ::
HitTime=%.3lf\n",titikPantul.getX(),titikPantul.getY(),minHitTime);
/** Tambah Sinar */
sinar[jumlahSinar++].set(titikPantul.getX(),titikPantul.getY(),0);
/** vektor normal dititik pantul */
Vektor V;
vektor perp;
perp.set(tembok.getY()*-1,tembok.getX(),0);
if(V.dotProduct(polygon[lokasiTEmbok[0]].get((lokasiTembok[1]+1)%polygon[lokasiTembok[0]].getJumlahInput()),perp)==-1)
{
{
/** negatifkan */
perp.set(perp.getX()*-1,perp.getY()*-1,0);
}
double panjang = perp.getPanjang();
vektor normal = perp.getNormal();
vektor nextSinar = getVektorPantul(currentSinar,normal);
return nextSinar;
}
/** Mouse handle Function */
void mouse(int button, int state, int x, int y){
switch(button){
case GLUT_LEFT_BUTTON:
/** onRelease, klik untuk menentukan titik2 polygon */
if(state==GLUT_UP && status < SELESAI_BUAT_POLYGON){
status = MEMBUAT_POLYGON;
if(polygon[jumlahPolygon].getJumlahInput()==MAX_INPUT)
{
printf();
break;
}
polygon[jumlahPolygon].add(x,SCREEN_H-y,0);
}
/** mengklik titik(Point P) yang dicari posisinya */
else if(state == GLUT_UP && status == SELESAI_BUAT_POLYGON){
print("klik titik P\n");
p.set(x,SCREEN_H - y,0);
status = KLIK_TITIK_P1;
}
/** Mengklik titik(Point P) yang dicari posisinya */
else if(state == GLUT_UP && status == KLIK_TITIK_P1) {
printf("Klik titik P1\n");
p1.set(x,SCREEN_H-y,0;
status = CARI_SINAR;
sinar[jumlahSinar++].set(p.getX(),p.getY(),p.getZ());
currentSinar.set(p1.getX() - p.getX(), p1.getY(),0);
}
break;
case GLUT_RIGHT_BUTTON;
/** Mengakhiri pembuatan titik2 untuk satu polygon */
if(state == GLUT_UP && status == MEMBUAT_POLYGON){
jumlahPolygon +=1;
status = SIAP_BUAT_POLYGON;
}
/* Mengakhiri pembuatan polygon2' */
else if(state == GLUT_UP && status == SIAP_BUAT_POLYGON){
status = SELESAI_BUAT_POLYGON;
}
}
}
/* display function */
void display(void){
if(jumlahSinar == MAX_SINAR)return;
vektor next;
if(status == CARI_SINAR)
{
next = getSinar();
currentSinar.set(next.getX(),next.getY(),next.getZ());
}
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,1.0);
printPolygon();
printPoint();
printSinar();
glEnd();
glFlush();
}
void myInit(void){
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(5);
glMatrixModel(GL_POJECTION);
glLoadIdentity();
glOrtho2D(0.0,SCREEN_W,0.0,SCREEN_H);
}
void idle(void){
glutPostRedisplay();
}
int main(int argc, char **argv){
/*GLUT MODE */
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(SCREEN_W,SCREEN_H);
glutInitWindowPosition(100,100);
glutCreateWindow("SOALNIIII");
glutMouseFunc(mouse);
gutDisplayFunc(display);
glutIdleFunc(idle);
myInit();
glutMainLoop();
return 0;
}