English 中文(简体)
第2D条
原标题:Position moving 2D object openGL
  • 时间:2011-03-10 19:19:08
  •  标签:
  • opengl

我的物体在X轴线上回落,然而,在X轴线上,它进一步正确。

这是我的法典,是怎么做的?

float moveRad = 0.0;
        moveRad = moveBee * (PI/180.0);     
        moveBee += 0.1;

        glPushMatrix();
            glTranslatef(50.0 * sinf(moveRad), -100,0);
            e[0] = new Platform(0, 0, 0, 40, 33, 40, 33, 00, textures[23], (50.0 * sinf(moveRad)), -100);
        glPopMatrix();

Platform.cpp creates the object like so:

glBegin(GL_QUADS);
        glTexCoord2f(0.0, 0.0); glVertex2f(x1,y1);
        glTexCoord2f(0.0, 1.0); glVertex2f(x2,y2);
        glTexCoord2f(1.0, 1.0); glVertex2f(x3,y3);
        glTexCoord2f(1.0, 0.0); glVertex2f(x4,y4);
    glEnd();
问题回答

我感觉到的是,对开放的GL是如何运作的误解。 你写道,“Platform.cpp制造了这样的物体:”和在法典中,在我能看到你重新创建由开放式GL矩阵中继行动环绕的一些Plattform级的事例之前,我会这样做。 我怀疑您的假设是,开放式利比里亚将在某种程度上“储存”这一“目标”。 www.un.org/Depts/DGACM/index_spanish.htm 这并不是“开放式”公司是如何运作的。 你从图表中重新思考。 开放式自由工并不是一幅画面。

开放式GL是一种图谋。 电话

glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0); glVertex2f(x1,y1);
    glTexCoord2f(0.0, 1.0); glVertex2f(x2,y2);
    glTexCoord2f(1.0, 1.0); glVertex2f(x3,y3);
    glTexCoord2f(1.0, 0.0); glVertex2f(x4,y4);
glEnd();

抽到屏幕上。 同样: 页: 1 在这些指挥发出后,这些指挥被开放的利比里亚人民解放联盟带走和遗忘。 开放式过渡矩阵用于改变绘图指令输入数据。 但同样没有坚持不懈。 必须根据所抽出的每个框架发出绘画指挥。 我首先认为,我可以重写你们的一些法典,但是,如果我可以这样说,它需要改写。

典型的开放式计算方案就是这样(我随意排除所有类别和类型定义,并期望对变数、成员和方法名称进行某种常识的解释)。

/* draw_scene is called on every iteration of the program main loop or
   the drawing callback handler to update the screen */
void Scene::draw_scene(ScreenInfo si)
{
    glViewport(si.viewport.x, si.viewport.y, si.viewport.width, si.viewport.height);
    glClearColor(this->clear.r, this->clear.g, this->clear.b, this->clear.a);
    glClearDepth(this->clear.d);
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    glDepthMask(GL_TRUE);
    glClear( (this->clear.color ? GL_COLOR_BUFFER_BIT) | 
             (this->clear.depth ? GL_DEPTH_BUFFER_BTT) );

    std::list<SceneObjects*> objects_by_distance = 
        sort_objects_by_direction(scene->objects,
                                  scene->active_camera->position
                                  scene->active_camera->direction);

    SceneObjects *closest_object = objects_by_distance.front();
    SceneObjects *farthest_object = objects_by_distance.back();

    float near_clip = max(NEAR_CLIP_LIMIT,
                      length(closest_object->position - scene->active_camera->position)
                      - closest_object->bounding_sphere.radius );

    float far_clip = min(FAR_CLIP_LIMIT,
                     length(farthest_object->position - scene->active_camera->position)
                     + farthest_object->bounding_sphere.radius );

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    switch( scene->projection.type ) {
    case Projection::perspective: {
        gluPerspective( scene->projection.fov, 
                        (float)si.viewport.width/(float)si.viewport.height,
                        near_clip, far_clip);
    } break;
    case Projection::orthographic: {
        float aspect = (float)si.viewport.width/(float)si.viewport.height;
        glOrtho( -0.5 * scene->projection.size * aspect, 0.5 * scene->projection.size * aspect
                 -0.5 * scene->projection.size           0.5 * scene->projection.size );
    } break;
    }

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    /* I normally disregard using gluLookAt, but in this case I use it
       to show as much as possible! */
    gluLookAt( scene->active_camera->position.x, scene->active_camera->position.y, scene->active_camera->position.z,
               scene->active_camera->position.x + scene->active_camera->direction.x,
               scene->active_camera->position.y + scene->active_camera->direction.y, 
               scene->active_camera->position.z + scene->active_camera->direction.z,
               scene->active_camera->up.x, scene->active_camera->up.y, scene->active_camera->up.z );

     for_each(scene->objects.begin(), scene->objects.end(), draw_object)
}

void draw_object(SceneObject *object)
{
     glMatrixMode(GL_MODELVIEW);
     glPushMatrix();

     glTranslatef(object->position.x, object->position.y, object->position.z);
     glRotatef(object->rotation.axis.angle, object->rotation.axis.x, object->rotation.axis.y, object->rotation.axis.z);

     GLfloat *(vertex_ptr[3][3]) = object->mesh->vertices;
     GLuint *vertex_indices = object->mesh->face_vertex_indices;
#ifdef USE_IMMEDIATE_MODE
     glBegin(GL_TRIANGLES);
     for(int i = 0; i < object->mesh->face_count; i++) {
            glNormalfv(&vertex_ptr[vertex_indices[i]][0]); 
         glTexCoord3fv(&vertex_ptr[vertex_indices[i]][1]);
           glVertex3fv(&vertex_ptr[vertex_indices[i]][2]);

            glNormalfv(&vertex_ptr[vertex_indices[i+1]][0]); 
         glTexCoord3fv(&vertex_ptr[vertex_indices[i+1]][1]);
           glVertex3fv(&vertex_ptr[vertex_indices[i+1]][2]);

            glNormalfv(&vertex_ptr[vertex_indices[i+2]][0]); 
         glTexCoord3fv(&vertex_ptr[vertex_indices[i+2]][1]);
           glVertex3fv(&vertex_ptr[vertex_indices[i+2]][2]);
     }
     glEnd();
#else
     glEnableClientState(GL_NORMAL_ARRAY);
     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     glEnableClientState(GL_VERTEX_ARRAY);

     /* This is direct vertex array mode.
        A more modern approach is using Vertex Buffer Objects, which reused this
        API, but adds further function calls. */
     glNormalPointer(GL_FLOAT, 3*3*sizeof(GLfloat), &vertex_ptr[0][0]);
     glTexCoordPointer(3, GL_FLOAT, 3*3*sizeof(GLfloat), &vertex_ptr[0][1]);
     glVertexPointer(3, GL_FLOAT, 3*3*sizeof(GLfloat), &vertex_ptr[0][2]);

     glDrawElements(GL_TRIANGLES, object->mesh->face_count*3, GL_UNSIGNED_INT, vertex_indices);
#endif
     glPopMatrix();
}

这是认真使用开放式GL的最基本方法。 我在此详细写道,请你说明如何使用否决权,以及它如何运作。

为什么在请<条码>gl Translatef时,你不会调整x-axis的比额表?

glTranslatef(amplitude * sinf(moveRad), -100,0);

I have a feeling you don t know exactly what your code is doing (correct me if I m wrong). If you want to move it to the right just add a number in here.

冰川融化(50.0) * sinf(moveRad)+30,-100,0;

如果是不必要的,我将更新我的回答。

我认为,你的问题是50.0* 恶毒,这将在-50至50之间分散。 添加价值而不是或增加价值。





相关问题
OpenGL 3D Selection

I am trying to create a 3D robot that should perform certain actions when certain body parts are clicked. I have successfully (sort of) implemented picking in that if you click on any x-plane part, it ...

CVDisplayLink instead of NSTimer

I have started to implement cvDisplayLink to drive the render loop instead of nstimer, as detailed in this technical note https://developer.apple.com/library/archive/qa/qa1385/_index.html Is it ...

Can the iPhone simulator handle PVR textures?

I have a really weird problem with PVR textures on the iPhone simulator- the framerate falls through the floor on the iPhone simulator, but on the iPhone itself it works just fine. Has anyone had any ...

Calculate fps (frames per second) for iphone app

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries ...

热门标签