GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Dec-2008, 23:56
roidel roidel is offline
New Member
 
Join Date: Dec 2008
Posts: 1
roidel is on a distinguished road

Looking for file: polygon.h


Hello, i found this code from an article, i want to buil it but i don't have file polygon.h Can you sent me file polygon.h for this code...???

Thanx

This is the code...

CPP / C++ / C 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;
}
Last edited by LuciWiz : 04-Dec-2008 at 23:58. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 05-Dec-2008, 12:05
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: file polygon.h


Quote:
Originally Posted by roidel
Hello, i found this code from an article,...

1. Since polygon.h is not a standard library function (not C, not C++, not GL), there is no way to know what should be in it. Have you looked everywhere in the article? If the article does not contain complete source code, is there a link to it somewhere? Is there a link to the author?

2. Even if we could magically come up with a suitable "polygon.h," it is highly likely that it contains prototypes but not implementations for some of the functions used in the program.

Bottom line: you probably need other files (maybe polygon.c or some such thing.)

I am guessing (but I could be wrong) that the same holds for "vector.h," since it is apparently a C program (Not C++), and there is no standard C library header named "vector.h."

Regards,

Dave
Regards,

Dave
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
After execution - Error cannot locate /Skin File? WSCH C++ Forum 1 05-Mar-2005 21:03
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28
CD Buring Failed skanth2000 Computer Hardware Forum 1 15-Nov-2003 04:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:31.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.