Так что у меня возникла проблема, когда мне кажется, что я всегда получаю местоположение последнего шара, когда запрашиваю это место. Как будто значения в объектах не назначаются должным образом, когда я объявляю объект.
Вот что у меня на данный момент
ball TestBall[2];
Объявление переменных внутри метода
void ball::Placeball() {
//TEMP TEST
TestBall[1].DrawBall(5,0.15,10,3,10);
//TEMP TEST
TestBall[2].DrawBall(5,0.15,10,3,30);
}
Метод My Draw Ball и способ передачи переменной
void ball::DrawBall(float radius, float mass, float x, float y, float z) {
xPos = x;
yPos = y;
zPos = z;
GLUquadricObj *quadratic;
quadratic = gluNewQuadric();
glPolygonMode(GL_FRONT,GL_FILL);
glPolygonMode(GL_BACK,GL_FILL);
gluQuadricNormals(quadratic,GLU_SMOOTH);
glTranslatef(x,y,z);
gluSphere(quadratic,radius,20,20);
glTranslatef(-x,-y,-z);
}
Передаваемая переменная, которую я не могу заставить работать
float ball::zPos
и как это получается
float ball::GetZ() const {
return zPos;
}
А потом, как я просто пытаюсь получить значение
cout << TestBall[1].GetZ() << endl; //should be 10
cout << TestBall[2].GetZ() << endl; //should be 30
ball.cpp :
float ball::xPos = 0;
float ball::yPos = 0;
float ball::zPos = 0;
ball::ball() { };
void ball::DrawBall(float radius, float mass, float x, float y, float z) {
xPos = x;
yPos = y;
zPos = z;
GLUquadricObj *quadratic;
quadratic = gluNewQuadric();
glPolygonMode(GL_FRONT,GL_FILL);
glPolygonMode(GL_BACK,GL_FILL);
gluQuadricNormals(quadratic,GLU_SMOOTH);
glTranslatef(x,y,z);
gluSphere(quadratic,radius,20,20);
glTranslatef(-x,-y,-z);
}
float ball::GetX() const {
return xPos;
}
float ball::GetY() const {
return yPos;
}
float ball::GetZ() const {
return zPos;
}
ball.h
#pragma once
class ball
{
private:
static float xPos;
static float yPos;
static float zPos;
public:
ball();
ball(float radius, float mass, float x, float y, float z){};
~ball(){};
static void DrawBall(float radius, float mass, float x, float y, float z);
static void UpdateBall(float speedx, float speedz);
static void Placeball();
float GetX() const;
float GetY() const;
float GetZ() const;
};
Оба значения читаются как 30, это та же проблема, если я увеличу размер массива объектов.
Скорее всего, я упускаю что-то простое.
Спасибо за ваше время.