Tiger_Vengeance
Tiger_Vengeance

Reputation: 131

Drawing an object through an array

Having some problems with this for loop to draw multiple numbers of the same object,

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

Redball is being called from a separate class,

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

Redball is defined at the top of Main.cpp

Ball Redball;  

Ball.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;
}

Just trying to draw 8 of these balls.

Upvotes: 0

Views: 227

Answers (2)

rerun
rerun

Reputation: 25505

That error means that . accessors are for real data. Structs Classes or uninons in this case you have a pointer to your class not an instance.

Try and see if that works for ya.

Redball[i]->Draw()

Upvotes: 2

sehe
sehe

Reputation: 392929

Perhaps you need this

Redball[i]->Draw(); 

But there is no way to tell

From the code you gave us

Upvotes: 3

Related Questions