【问题标题】:Drawing an object through an array通过数组绘制对象
【发布时间】:2011-04-14 17:26:53
【问题描述】:

这个for循环在绘制多个相同对象时遇到了一些问题,

for (int i = BALL_RED_START; i<BALL_RED_END;i++)
{
    glColor3f(1,0,0);
    Redball[i].Draw(); 
}

Redball 正在从一个单独的类中调用,

I get error:2228, left of .Draw must have class/struct/union.

Redball 定义在 Main.cpp 的顶部

Ball Redball;  

球.cpp:

include "Ball.h"
include "Vector2f.h"
include "Vector3f.h"
include "Glut/glut.h"
include "GL/gl.h"
include "GL/glu.h"

Ball::Ball(void)
{
    Vector3f Temp_position;
    position = Temp_position;
    Vector3f Temp_velocity;
    velocity = Temp_velocity;
}

Ball::~Ball(void)
{
}

void Ball::SetPos(Vector3f New_position)
{
    position = New_position;
}

void Ball::Draw()
{
    glPushMatrix();
    glTranslatef(position.X(), position.Y(), position.Z());
    glColor3d(1, 0, 0);
    glutSolidSphere(0.3, 50, 50);
    glPopMatrix();
}

void Ball::SetVel(Vector3f New_velocity)
{
    velocity = New_velocity;
}

Vector3f Ball::GetPos()
{
    Vector3f temp;
    temp = position;
    return temp;
}

只是想抽出 8 个这样的球。

【问题讨论】:

  • 你不认为我们想知道.Draw 的左边是什么?我的朋友,红球是如何被宣布的?
  • 我试过了 -> 到目前为止没有运气!
  • 当您有更多信息时,也许可以在my answer 上给我留言,我不必经常回来查看

标签: c++ arrays opengl object


【解决方案1】:

也许你需要这个

Redball[i]->Draw(); 

但是没有办法告诉

根据你给我们的代码

【讨论】:

  • 恐怕更新(谢谢)仍然遗漏了关键部分。头文件可能为 Ball 定义了 operator[](...),这是关键的缺失位 :)
【解决方案2】:

那个错误意味着 .访问器用于真实数据。在这种情况下,Structs Classes 或 uninons 你有一个指向你的类而不是实例的指针。

试试看是否适合你。

Redball[i]->Draw()

【讨论】:

    猜你喜欢
    • 2019-05-05
    • 2022-11-27
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 2019-07-18
    • 2018-10-14
    相关资源
    最近更新 更多