hello… this is m code… it runs and you can see its result…
the thinhg is that i don not know if my prokection is good enough and if the coordinates given are the appropriate?? can anyone try this and give me some other coordinates- or change sth else??
so can anyone compile and run it… it will olny take a couple of minutes… what i do need if i must change any coordinates in gluPerspective or change it t gluFrustum or change my gluLookAt so as to have a better-nicer result?? gust some extra testings because time is runnig out…
#include <windows.h>
#include <stdlib.h>
#include <glut.h>
#include <math.h>
#include <stdio.h>
GLsizei width=640;
GLsizei height=480;
#define MAX_X 100
#define MAX_Y 100
int AR_GRAM;//apothikefsi ari8mo grammon
int AR_STIL;
GLsizei xwmin=-50;
GLsizei xwmax=50;
GLsizei ywmin=-50;
GLsizei ywmax=50;
int h,i,j;
int pos1,pos2;//thesi tou xaraktira
int fan1,fan2;//thesi toy fantasmatos
int num;
#define PI 3.14159
#define circlePoints 128
char direct[4]={'w','a','s','d'};
char x[MAX_X][MAX_Y];
char init[MAX_X][MAX_Y];
char fand,help5;
int axisx;//endexomenh nea 8esi tou hrwa
int axisy;
int flag=0;
int flaga=1,flagw=1,flags=1,flagd=1;
int fruits=0;
int flagdot=0,flagdotnext=0;
int dotx,doty,statx,staty;
void readtxt() {
FILE *fp;
int w=0,r=0,e;
fp=fopen("C:\\opengl\\map.txt", "r");[color:#990000]// give your exact path[/color]
while ( !feof(fp)) {
e=getc(fp);
if (e!='
')
{
x[w][r++]=e;
if (AR_STIL<r) AR_STIL=r;
}
else
{
r=0;
w++;
}
}
AR_STIL=AR_STIL-1;
AR_GRAM=w;
fclose(fp);
}
void makecopy() {
int qq,ww;
for (qq=0;qq<=AR_GRAM;qq++){
for (ww=0;ww<AR_STIL;ww++) {
init[qq][ww]=x[qq][ww];
}
}
}
void drawcube(int a1,int a2, int b1, int b2) {//a->cnt, b->temp
glPushMatrix();
glTranslatef( (GLfloat) b1+a1/2, (GLfloat) b2+a2/2, 0);
if (x[i][j]=='2') glRotatef(45,1,0,0);
glScalef(1.0,a2/a1,1.0);
if (a1<a2)
glutSolidCube(a1);
else
glutSolidCube(a2);
glColor3f(1,0,1);
if (a1<a2)
glutWireCube(a1);
else
glutWireCube(a1);
glPopMatrix();
}
void drawsphere(int a1, int a2, int b1, int b2) {
glPushMatrix();
glTranslatef( (GLfloat) b1+a1/2, (GLfloat) b2+a2/2, 0);
glutSolidSphere(a1,128,128);
glPopMatrix();
}
void drawcon(int a1, int a2, int b1, int b2) {
glPushMatrix();
glTranslatef( (GLfloat) b1+a1/2, (GLfloat) b2+a2/2, 0);
glutSolidCone(a1/2,a2,64,64);
glPopMatrix();
}
void drawdot(int a1, int a2, int b1, int b2) {
glPushMatrix();
glTranslatef( (GLfloat) b1+a1/2, (GLfloat) b2+a2/2, 0);
glutSolidCube(3);
glPopMatrix();
}
void timerFunction(int value) {
printf("timerFunctionCallBack
");
int g,p;
for (g=AR_GRAM;g>=0;g--) {
for (p=0;p<AR_STIL;p++) {
if (x[g][p]=='-') {x[g][p]='2'; printf ("p=%d --g=%d
",g,p); return ;}
}
}
glutPostRedisplay();
glutTimerFunc(15000,timerFunction,10); // den epidraei sto programma giati?? dn eprepe na to ksanaenergopoiei??
}
void display()
{
GLsizei temp1,temp2=-50,cnt1,cnt2;
glClearColor(1,1,1,0);
glClear(GL_COLOR_BUFFER_BIT);
cnt1=(2*xwmax/AR_STIL);
cnt2=(2*ywmax/(AR_GRAM+1));
for (i=AR_GRAM;i>=0;i--) {//gia na sxediastei opws to vlepoume stin pista
temp1=-50;//na arxizoun apo panw oi 8eseis (0,0) ktl
for (j=0;j<AR_STIL;j++) {
if (x[i][j]=='*') {
glColor3f(1,0,0);
drawcube(cnt1,cnt2,temp1,temp2);
}
else if (x[i][j]=='2'){
glColor3f(0,1,0);
drawcube(cnt1,cnt2,temp1,temp2);
fruits=fruits+1;
}
else if (x[i][j]=='#') {
glColor3f(0,0,1);
drawsphere(cnt1,cnt2,temp1,temp2);
fan1=i;//apo8ikefsi 8eseon fantasmatos
fan2=j;
}
else if (x[i][j]=='@') {
glColor3f(1,1,0);
drawsphere(cnt1,cnt2,temp1,temp2);
pos1=i;//apo8ikefsi 8eseon irwa
pos2=j;
}
else if (x[i][j]=='1') {
glColor3f(1,0,1);
drawdot(cnt1,cnt2,temp1,temp2);
}
else if (x[i][j]=='3') {
glColor3f (0,1,1);
drawcon(cnt1,cnt2,temp1,temp2);
}
temp1=temp1+cnt1;
}
temp2=temp2+cnt2;
}
glutSwapBuffers();
}
int main (int argc, char** argv)
{
glutInit(&argc,argv);
glutInitWindowPosition(50,50);
glutInitWindowSize(width,height);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow("attempt1");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-50,50,-50,50,-2000,2000);
//glFrustum(-150,150,-150,150,0,2000);
gluPerspective(70,1,0,2000);
glMatrixMode(GL_MODELVIEW);
gluLookAt(-30,-30,90,0,0,0,0,1,0);
readtxt();
glutDisplayFunc(display);
glutTimerFunc(5000,timerFunction,0);
glutMainLoop();
return 0;
}
the .txt file is…
**************
**--2--1-----*
*-----1#1----*
*---2--1---@-*
**************
PLZ HELP ME:)