English 中文(简体)
• 帮助了解一些开放的GL阵列
原标题:Help understanding some OpenGL stuff

我正在与一些法典合作,以建立一个小三角地带,把钥匙带走。 我想提出一个独立移动的第二个目标。 在我遇到麻烦的地方,我建立了第二位行动者,但无法采取行动。 如此,我只说一点一点,看谁能够帮助。

ogl_test.cpp

#include "platform.h"
#include "srt/scheduler.h"

#include "模式h"
#include "controller.h"

#include "model_module.h"
#include "graphics_module.h"

class blob : public actor {
public:
    blob(float x, float y) : actor(math::vector2f(x, y)) { }

    void render() {
        transform();

        glBegin(GL_TRIANGLES);
            glVertex3f(0.25f, 0.0f, -5.0f);
            glVertex3f(-.5f, 0.25f, -5.0f);
            glVertex3f(-.5f, -0.25f, -5.0f);
        glEnd();
        end_transform();
    }
    void update(controller& c, float dt) {
        if (c.left_key) {
            rho += pi / 9.0f * dt;
            c.left_key = false;
        }
        if (c.right_key) {
            rho -= pi / 9.0f * dt;
            c.right_key = false;
        }
        if (c.up_key) {
            v += .1f * dt;
            c.up_key = false;
        }
        if (c.down_key) {
            v -= .1f * dt;
            if (v < 0.0) { v = 0.0; }
            c.down_key = false;
        }
        actor::update(c, dt);
    }
};

class enemyOne : public actor {
public:
    enemyOne(float x, float y) : actor(math::vector2f(x, y)) { }

    void render() {
        transform();

        glBegin(GL_TRIANGLES);
            glVertex3f(0.25f, 0.0f, -5.0f);
            glVertex3f(-.5f, 0.25f, -5.0f);
            glVertex3f(-.5f, -0.25f, -5.0f);
        glEnd();
        end_transform();
    }
    void update(controller& c, float dt) {
        if (c.left_key) {
            rho += pi / 9.0f * dt;
            c.left_key = false;
        }
        if (c.right_key) {
            rho -= pi / 9.0f * dt;
            c.right_key = false;
        }
        if (c.up_key) {
            v += .1f * dt;
            c.up_key = false;
        }
        if (c.down_key) {
            v -= .1f * dt;
            if (v < 0.0) { v = 0.0; }
            c.down_key = false;
        }
        actor::update(c, dt);
    }
};

int APIENTRY WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    char* lpCmdLine,
    int nCmdShow
)
{

    model m;
    controller control(m);

    srt::scheduler scheduler(33);
    srt::frame* model_frame = new srt::frame(scheduler.timer(), 0, 1, 2);
    srt::frame* render_frame = new srt::frame(scheduler.timer(), 1, 1, 2);
    model_frame->add(new model_module(m, control));

    render_frame->add(new graphics_module(m));

    scheduler.add(model_frame);
    scheduler.add(render_frame);

    blob* prime = new blob(0.0f, 0.0f);
    m.add(prime);
    m.set_prime(prime);

    enemyOne* primeTwo = new enemyOne(2.0f, 0.0f);
    m.add(primeTwo);
    m.set_prime(primeTwo);

    scheduler.start();
    control.start();

    return 0;
}

模式h

#include <vector>
#include "vec.h"

const double pi = 3.14159265358979323;

class controller;

using math::vector2f;

class actor {
public:
    vector2f P;
    float theta;
    float v;
    float rho;

    actor(const vector2f& init_location) :
        P(init_location),
        rho(0.0),
        v(0.0),
        theta(0.0)
    { }
    virtual void render() = 0;
    virtual void update(controller&, float dt) {
        float v1 = v;
        float theta1 = theta + rho * dt;
        vector2f P1 = P + v1 * vector2f(cos(theta1), sin(theta1));
        if (P1.x < -4.5f || P1.x > 4.5f) { P1.x = -P1.x; }
        if (P1.y < -4.5f || P1.y > 4.5f) { P1.y = -P1.y; }
        v = v1;
        theta = theta1;
        P = P1;
    }

protected:
    void transform() {
        glPushMatrix();
        glTranslatef(P.x, P.y, 0.0f);
        glRotatef(theta * 180.0f / pi, 0.0f, 0.0f, 1.0f); //Rotate about the z-axis
    }
    void end_transform() {
        glPopMatrix();
    }
};

class model {
private:
    typedef std::vector<actor*> actor_vector;
    actor_vector actors;
public:
    actor* _prime;

    model() { }

    void add(actor* a) {
        actors.push_back(a);
    }
    void set_prime(actor* a) {
        _prime = a;
    }
    void update(controller& control, float dt) {
        for (actor_vector::iterator i = actors.begin(); i != actors.end(); ++i) {
            (*i)->update(control, dt);
        }
    }
    void render() {
        for (actor_vector::iterator i = actors.begin(); i != actors.end(); ++i) {
            (*i)->render();
        }
    }
};
最佳回答

if (c.left_key) {
   rho += pi / 9.0f * dt;
   c.left_key = false; // <-- HERE
}

在每个框架之后清除键盘状态不应当是任何单一行为者的关切,控制者本身应当这样做。

问题回答

blob和敌人 两者都有一项更新职能,即检查arrow的钥匙,看看是否迁移。 如果你在更新职能之一发表所有声明,则不应再作任何改动。 或者,你可以改变更新功能中的说法,以检查其他关键人物,并利用这些钥匙控制其他物体。

<> >>> ><>>>><>>>>>><>>>>>>>;>>><>>>> >>> > > > > > > > > > > > > > >>>>>>> > >>>> > > >> > > > > >>>> > > > > > > > > > > > > > > > > > > ”。 Ei>,<>;<>;<>;>;>;>;<......>;>。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签