English 中文(简体)
将开放式模型带入一个集装箱,将其放在另一个集装箱之后。
原标题:Loading Opengl models into a container and calling them one after the other

I m a newbie to programming and I want to write conditional statements for OpenGL models such that when I click a button it loads a Triangle model in a stl vector container. When I click the same button again, it loads another model say Quad in the container, and for further button clicks it loads more models such as Cube, Toroid and so on.... I m also going to include an Undo button to remove the last loaded model.

请允许我通过撰写这种有条件声明,说明如何将大约4个模型装入每 but点点击的STL矢量集装箱,以及单单载荷。

class Shapes {
public:
    Shapes(){}
    ~Shapes(){}
    virtual void draw() 
    { 
        std::cout << "Base function called" << std::endl; 
    }

};

class Models : public Shapes 
{    
  public: Models() 
    {

    }

    ~Models() {}

    virtual void draw() 
    {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
            glLoadIdentity(); 
            glTranslatef(-1.5f, 0.0f, -6.0f); 
            glBegin(GL_TRIANGLES); 
               glColor3f(1.0f, 0.0f, 0.0f); // Red color
               glVertex3f( 0.0f,  1.0f, 0.0f); // Top
               glColor3f(0.0f, 1.0f, 0.0f); // Green color
               glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
               glColor3f(0.0f, 0.0f, 1.0f); // Blue color
               glVertex3f( 1.0f, -1.0f, 0.0f); // Bottom Right
            glEnd(); // End drawing the triangle


    }

};

Draw_All_models{

  std::vector<Shapes*> myObjects;

  myObjects.push_back(new Triangle());
  myObjects.push_back(new Quad());
  //more models...

  void RenderScene() 
  {
    std::vector<Shapes*>::iterator it;
    for(it = myObjects.begin() ; it != myObjects.end; ++it) (*it)->draw();
     }
}
最佳回答

首先需要理解的是,开放式的GL确实没有维持一个景象或模型。 这一切都是在你的要求下,把一点点、线或三角点推到屏幕上。 一旦你发现精神消化,情况就会明显:

储存一份清单,其中每项内容都编码了哪些内容。 然后,你需要某种方法,来核对清单(或阵列),并且每个要素都向正确职能(也由你撰写)发送,以便按照要素的数据提取地貌。

例如,在C++中,你可能有一些基类类别<代码>Model,从中选取Box,Sphere>,Torus 等。 <代码>Model界定了虚拟方法draw<>/code>。 之后,您将编成一个<代码>std:list<Model*> Model, 您可通过<代码>检索(d:list<Model*> I = 模型.begin(); I!=模型.end(); I++){(*I)->draw();}。

附 件 这样,方法就能够适当提供每一种模式。

问题回答

暂无回答




相关问题
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?

热门标签