Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[Open GL] glTranslatef

Ostatnio zmodyfikowano 2012-09-09 14:35
Autor Wiadomość
yoogi
Temat założony przez niniejszego użytkownika
[Open GL] glTranslatef
» 2012-09-08 17:59:30
Witam, chcę przesunąć obiekt do tyłu :)

Jeżeli daje:
glTranslatef( 0.0f, 0.0f, - 1.0f );
 to się pomniejszy, ale jeżeli w trzecim argumencie dam, na przykład -1.5, to kawałek obiektu zostaje obcięty. Według mnie scena się kończy i pytanie, jak ja powiększyć ? :)
P-64603
m4tx
» 2012-09-08 18:02:45
Według mnie scena się kończy i pytanie, jak ja powiększyć ? :)
Ustawienia perspektywy zmień. Far plane się to zwie z tego co kojarzę.
P-64605
yoogi
Temat założony przez niniejszego użytkownika
» 2012-09-08 18:15:11
gluPerspective( 45.0f,( GLfloat ) ev.size.width /( GLfloat ) ev.size.height, 0.1f, 100.0f );

Zwiększam ostatni argument i nadal nic
P-64609
Gabes
» 2012-09-08 18:56:41
Zostało ci jeszcze
glScalef( 4.0, 4.0, 4.0 );
Pewne funkcje muszą być podawane we właściwej kolejności.
P-64615
yoogi
Temat założony przez niniejszego użytkownika
» 2012-09-08 19:17:49
@up, zobacz na to:
C/C++
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>

#pragma comment(lib,"sfml-window.lib")
#pragma comment(lib,"sfml-system.lib")
#pragma comment(lib,"sfml-graphics.lib")

#pragma comment(lib,"OpenGL32.lib")
#pragma comment(lib,"glu32.lib")

int main()
{
    sf::Window window( sf::VideoMode( 800, 600 ), "OpenGL", sf::Style::Default, sf::ContextSettings( 32 ) );
    window.setVerticalSyncEnabled( true );
   
    int i = 0;
   
    bool running = true;
    while( running )
    {
        sf::Event ev;
        while( window.pollEvent( ev ) )
        {
            if( ev.type == sf::Event::Closed )
            {
                running = false;
            }
            else if( ev.type == sf::Event::Resized )
            {
                glViewport( 0, 0, ev.size.width, ev.size.height );
               
                glMatrixMode( GL_PROJECTION );
                glLoadIdentity();
                gluPerspective( 45.0f,( GLfloat ) ev.size.width /( GLfloat ) ev.size.height, 0.1f, 100.0f );
            }
        }
       
        i++;
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glLoadIdentity();
        glScalef( 4.0, 4.0, 4.0 );
        glTranslatef( 0.0f, 0.0f, - 1.0f );
        glRotatef( i, 0.0f, 1.0f, 0.0f );
        glBegin( GL_TRIANGLES );
        glColor3f( 1.0f, 0.0f, 0.0f );
        glVertex3f( 0.0f, 1.0f, 0.0f );
        glColor3f( 0.0f, 1.0f, 0.0f );
        glVertex3f( - 1.0f, - 1.0f, 1.0f );
        glColor3f( 0.0f, 0.0f, 1.0f );
        glVertex3f( 1.0f, - 1.0f, 1.0f );
        glColor3f( 1.0f, 0.0f, 0.0f );
        glVertex3f( 0.0f, 1.0f, 0.0f );
        glColor3f( 0.0f, 0.0f, 1.0f );
        glVertex3f( 1.0f, - 1.0f, 1.0f );
        glColor3f( 0.0f, 1.0f, 0.0f );
        glVertex3f( 1.0f, - 1.0f, - 1.0f );
        glColor3f( 1.0f, 0.0f, 0.0f );
        glVertex3f( 0.0f, 1.0f, 0.0f );
        glColor3f( 0.0f, 1.0f, 0.0f );
        glVertex3f( 1.0f, - 1.0f, - 1.0f );
        glColor3f( 0.0f, 0.0f, 1.0f );
        glVertex3f( - 1.0f, - 1.0f, - 1.0f );
        glColor3f( 1.0f, 0.0f, 0.0f );
        glVertex3f( 0.0f, 1.0f, 0.0f );
        glColor3f( 0.0f, 0.0f, 1.0f );
        glVertex3f( - 1.0f, - 1.0f, - 1.0f );
        glColor3f( 0.0f, 1.0f, 0.0f );
        glVertex3f( - 1.0f, - 1.0f, 1.0f );
        glEnd();
       
        window.display();
    }
    return 0;
}
P-64624
SeaMonster131
» 2012-09-08 20:41:43
C/C++
gluPerspective( 45.0f,( GLfloat ) ev.size.width /( GLfloat ) ev.size.height, 0.1f, 100.0f );
Zwiększam ostatni argument i nadal nic

Hm.. może spróbuj dać to
C/C++
glViewport( 0, 0, ev.size.width, ev.size.height );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0f,( GLfloat ) ev.size.width /( GLfloat ) ev.size.height, 0.1f, 100.0f );
nie tylko przy zmianie wielkości okna, ale też od razu przy tworzeniu okna?

I ja scaluje obiekty poprzez glTranslatef() i wszystko gra..
P-64631
Gabes
» 2012-09-08 20:52:42
C/C++
else if( ev.type == sf::Event::Resized )
{
    glViewport( 0, 0, ev.size.width, ev.size.height );
    glClearColor( 0.5, 0.5, 0.5, 0.0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45.0f,( GLfloat ) ev.size.width /( GLfloat ) ev.size.height, 0.1f, 100.0f );
}
}

i++;
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0f, 0.0f, - 4.0f );
glRotatef( i, 0.0f, 1.0f, 0.0f );
glBegin( GL_TRIANGLES );
Może tak.
P-64635
yoogi
Temat założony przez niniejszego użytkownika
» 2012-09-08 20:54:10
@up, elegancko chodzi :)

C/C++
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
gluPerspective( 45.0f,( GLfloat ) 800 /( GLfloat ) 600, 0.1f, 100.0f );
glScalef( 4.0, 4.0, 4.0 );
glTranslatef( 0.0f, 0.0f, - 7.0f );
glRotatef( i, 0.0f, 1.0f, 0.0f );
P-64636
« 1 » 2
  Strona 1 z 2 Następna strona