Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:

Soutěž

Sponzorem soutěže je:

IDIF

 

Kde se koná výstava fotografií Luďka Vojtěchovského?

V dnešní soutěži hrajeme o:



transformacie

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: transformacie

Autor: timwood

12:54:04 10.09.2011

uz to ide. ale neviem preco.

namiesto toho:

[code]
glPushMatrix(); // - ulozenie aktualneho stavu transformacie

if( camera_on )
{
camera();
}


pipe();



if( cross_on )
{
cross();
}


if( grid_on )
{
grid();
}

glPopMatrix();// - obnovenie predchadzajuceho stavu transformacie
[/code]

som napisal toto:

[code]
glPushMatrix(); // - ulozenie aktualneho stavu transformacie

if( camera_on )
{
camera();
}


if( cross_on )
{
cross();
}

pipe();

if( grid_on )
{
grid();
}

glPopMatrix();// - obnovenie predchadzajuceho stavu transformacie
[/code]

Teda prehodil som vykreslovanie, pipe() za cross(). Ale to si asi budem musiet zvykat na take zvlastnosti.

Citovat příspěvek

 

Re: transformacie

Autor: nou

20:22:58 07.09.2011

a co vlastne nefunguje?

Citovat příspěvek

 

transformacie

Autor: timwood

20:57:33 06.09.2011

zdravim

Mam problem s transformaciami glTranslate. Nizsie posielam pre istotu cely kod, nie je dlhy a pomerne jednoduchy. [bold]Hrubo[/bold] zvyraznene casti nefunguju a neviem preco. Prechadzal som cely kod viac krat, ale nechce zobrazit funkciu [bold]cross()[/bold] pre vykreslenie [bold]osoveho kriza[/bold]. Vobec nechapem preco, ked predtym vykresluje funkciu grid() a pritom je napisana rovnakym sposobom.

Zrejme bude problem v spravnom umiestneni funkcii [bold]glPushMatrix()[/bold] a [bold]glPopMatrix()[/bold]. Skusal som ich rozne umiestnenie vo funkcii Display(), ale prakticky to funguje len tak ako je to napisane teraz (zhruba).

Fakt uz potom neviem, kde by mohla byt chyba..


[code]
#include
#include
#include
#include
#include


#define PI 3.14159265f

float r = 0.0;
float xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 0, angle = 0.0;
float lastx, lasty;

int mousePosX, mousePosY;
int windowWidth = 1024, windowHeight = 768;
int windowPosWidth = 500, windowPosHeight = 100;

bool grid_on = true, cross_on = true, camera_on = false, hud_1_on = true, hud_2_on = true;



void init(void)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.627, 0.627, 0.627, 1.0);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable( GL_COLOR_MATERIAL );
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glutWarpPointer(windowWidth / 2, windowHeight / 2);
}



void camera(void)
{
glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glTranslated(-xpos,-ypos,-zpos);
}


void pipe(void)
{
glTranslatef(10,0,0);

glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Blue
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange
glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Back)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Back)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back)
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Back)
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)

glEnd();
}


void grid(void)
{

int rows = 100;
int columns = 100;

glTranslatef(-50, 0, -50);
glDisable(GL_LINE_SMOOTH);

glBegin(GL_LINES);

for(int i = 0; i <= rows; i++)
{
glColor3f(0.45, 0.45, 0.45);
glVertex3f(0, 0, i);
glVertex3f(columns, 0, i);
}

for( int i = 0; i <= columns; i++)
{
glColor3f(0.45, 0.45, 0.45);
glVertex3f(i, 0, 0);
glVertex3f(i, 0, rows);
}

glEnd();

}

void cross(void)
{
glTranslatef(0,0,0);

glEnable(GL_LINE_SMOOTH);
glLineWidth(1.0);

glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(0.7, 0.1, 0);
glVertex3f(1, 0, 0);
glVertex3f(0.7, -0.1, 0);
glVertex3f(1, 0, 0);
glVertex3f(0.7, 0, 0.1);
glVertex3f(1, 0, 0);
glVertex3f(0.7, 0, -0.1);
glVertex3f(1, 0, 0);

glEnd();

glBegin(GL_LINES);
glColor3f(0, 1, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, 1, 0);
glVertex3f(0.1, 0.7, 0);
glVertex3f(0, 1, 0);
glVertex3f(-0.1, 0.7, 0);
glVertex3f(0, 1, 0);
glVertex3f(0.0, 0.7, 0.1);
glVertex3f(0, 1, 0);
glVertex3f(0.0, 0.7, -0.1);
glVertex3f(0, 1, 0);
glEnd();

glBegin(GL_LINES);
glColor3f(0, 0, 1);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 1);
glVertex3f(0.0, -0.1, 0.7);
glVertex3f(0, 0, 1);
glVertex3f(0.0, 0.1, 0.7);
glVertex3f(0, 0, 1);
glVertex3f(0.1, 0.0, 0.7);
glVertex3f(0, 0, 1);
glVertex3f(-0.1, 0.0, 0.7);
glVertex3f(0, 0, 1);
glEnd();

}


void drawBitmapText(char *string, float x, float y, float z)
{
char *c;
glRasterPos3f(x, y, z);

for (c=string; *c != '\0'; c++)
{
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *c);
}
}


void HUD_1()
{
glColor3f(0.20, 0.20, 0.20);
drawBitmapText("Press C to switch to camera mode", 700, 30, 0);
drawBitmapText("Press G to on/off grid view", 700, 45, 0);
drawBitmapText("Press K to on/off cross view", 700, 60, 0);
drawBitmapText("Camera mode behaviors:", 700, 90, 0);
drawBitmapText("Press W to move forwards", 715, 105, 0);
drawBitmapText("Press S to move backwards", 715, 120, 0);
drawBitmapText("Press A to strafe left", 715, 135, 0);
drawBitmapText("Press D to strafe right", 715, 150, 0);
drawBitmapText("Press Q and Z to move up and down", 715, 165, 0);
drawBitmapText("Press M to hide help", 700, 195, 0);
}


void HUD_2()
{
char spr[100];

glColor3f(0.20, 0.20, 0.20);

drawBitmapText("Camera", 30, 30, 0);
sprintf(spr, "Position: x:%f y:%f z:%f", xpos, ypos, zpos);
drawBitmapText(spr, 45, 45, 0);
sprintf(spr, "UpDown rotation: %f", yrot);
drawBitmapText(spr, 45, 60, 0);
sprintf(spr, "LeftRight rotation: %f", xrot);
drawBitmapText(spr, 45, 75, 0);
drawBitmapText("Mouse", 30, 105, 0);
sprintf(spr, "Position: x:%d y:%d", mousePosX, mousePosY);
drawBitmapText(spr, 45, 120, 0);
drawBitmapText("Press N to hide help", 30, 150, 0);
}


void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0,windowWidth,windowHeight,0);
glMatrixMode(GL_MODELVIEW);

if( hud_1_on )
{
HUD_1();
}

if( hud_2_on )
{
HUD_2();
}

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)windowWidth / (GLfloat)windowHeight, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);


glPushMatrix(); // - ulozenie aktualneho stavu transformacie

if( camera_on )
{
camera();
}


pipe();



if( cross_on )
{
[bold]cross();[/bold]
}


if( grid_on )
{
grid();
}

glPopMatrix();// - obnovenie predchadzajuceho stavu transformacie

glutSwapBuffers();
angle++;
}


void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);

glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
}


void keyboard(unsigned char key, int x, int y)
{

if (key == 'g')
{
if( grid_on == false)
{
grid_on = true;
}
else
{
grid_on = false;
}
}

if (key == 'k')
{
if( cross_on == false)
{
cross_on = true;
}
else
{
cross_on = false;
}
}

if (key == 'c')
{
if( camera_on == false)
{
camera_on = true;
glutSetCursor(GLUT_CURSOR_NONE);
}
else
{
camera_on = false;
glutSetCursor(GLUT_CURSOR_INHERIT);

}
}

if (key == 'm')
{
if( hud_1_on == false)
{
hud_1_on = true;
}
else
{
hud_1_on = false;
}
}

if (key == 'n')
{
if( hud_2_on == false)
{
hud_2_on = true;
}
else
{
hud_2_on = false;
}
}


if (key=='q')
{
ypos += 1;

}

if (key=='z')
{
ypos -= 1;

}

if (key=='w')
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad)) ;
zpos -= float(cos(yrotrad)) ;
ypos -= float(sin(xrotrad)) ;
}

if (key=='s')
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos -= float(sin(yrotrad));
zpos += float(cos(yrotrad)) ;
ypos += float(sin(xrotrad));
}

if (key=='d')
{
float yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xpos += float(cos(yrotrad)) * 0.5;
zpos += float(sin(yrotrad)) * 0.5;
}

if (key=='a')
{
float yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xpos -= float(cos(yrotrad)) * 0.5;
zpos -= float(sin(yrotrad)) * 0.5;
}

if (key==27)
{
exit(0);
}
}

void mouseMovement(int x, int y)
{
int diffx = x - lastx;
int diffy = y - lasty;
lastx = x;
lasty = y;
xrot += (float) diffy;
yrot += (float) diffx;

mousePosX = x;
mousePosY = y;
}

void main(int argc, char **argv)
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize( windowWidth, windowHeight );
glutInitWindowPosition( windowPosWidth, windowPosHeight );
glutCreateWindow( "Rury" );
init();
glutDisplayFunc( display );
glutIdleFunc( display );
glutReshapeFunc( reshape );
glutPassiveMotionFunc(mouseMovement);
glutKeyboardFunc( keyboard );

glutMainLoop();
}

[/code]

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: