-
September 13th, 2012, 11:24 PM
#1
Am needing help, perhaps, with an easy, hopefully, OpenGL Assignment.
Basically I have a turtle, not a visible one, but it's called "Turtle Graphics" and it draws, based on stuff from the input files, or it doesn't draw but moves.
move() moves but doesn't draw.
trace() draws and moves.
turn() turns the angle the "Turtle" is facing counter-clockwise by some angle.
I am supposed to keep track of the states (position x and y, and the angle/direction).
I was wondering, first off, since I'm using inner classes, whether my setup is right. I have a .h and .cpp file.
I'm actually using QTCreator, not Microsoft Visual C++, and it may be less visual oriented, though it does involve some GUIs as it does need menus.
Here's what I have so far:
Turtle.h:
Code:
class Turtle
{
private:
float angle;
float position_x;
float position_y;
State state;
stack<State> states;
class State
{
private:
float angle;
float position_x;
float position_y;
public:
State();
State(float position_x, float position_y, float angle);
};
public:
Turtle();
Turtle(float position_x, float position_y, float angle);
void setState(State state);
State getState();
~Turtle();
void turn(float angle);
void trace(float direction);
void move(float direction);
void push();
void pop();
};
Turtle.cpp:
Code:
Turtle::Turtle()
{
this->angle = 0.0f; // I think that's right
this->x_position = 0.0f;
this->y_position = 0.0f;
this->state = State(x_position, y_position, angle);
}
Turtle::Turtle(float position_x, float position_y, float angle)
{
this->position_x = position_x;
this->position_y = position_y;
this-> angle = angle;
this->state = State(x_position, y_position, angle);
}
Turtle::~Turtle()
{
}
Turtle::State::State()
{
this->position_x = 0.0;
this->position_y = 0.0;
this-> angle = 0.0;
}
Turtle::State::State(float position_x, float position_y, float angle)
{
this->position_x = position_x;
this->position_y = position_y;
this->angle = angle;
}
void Turtle::setState(Turtle::State state)
{
this->state = state;
}
Turtle::State Turtle::getState()
{
return this->state;
}
void Turtle::turn (float angle)
{
this->angle = this-> angle + angle;
}
void Turtle::move (float pos)
{
this->position_x = this->position_x + (pos * cos (this->angle));
this -> position_y = this->position_y + (pos * sin(this->angle));
}
void Turtle::trace(float pos)
{
// draw line between current position and new position.
}
void Turtle::push()
{
states.push(this->getState());
}
void Turtle::pop()
{
this->setState(states.pop());
}
int main()
{
}
I'm not sure if there is an actual class called "stack" in C++, it could be going by another name, but you probably get what I meant.
I also am not sure if there is a push and pop method in the stack class of C++. They might go by another name. (I'm more used to the Java names.)
First of all, did I use too many :: or not enough :: when referring to the inner class State inside of Turtle.cpp?
The first four things it'll read in are parameters for the window-world or some term that involved the word "world" and involved a GUI window. Might be a dimension.
The next ones after that are either
push
pop
move and (a float)
trace and (a float)
turn and (a float)
For instance
move 100.3821
trace -183.002
turn -300.1002
pop
push
There could be bogus commands, he warned us that he put one in there on purpose so that we have to test to make sure it's a valid command, which makes things a tiny bit harder.
The OpenGL part should only involve the one that sets the window bounds, or something like that, and the one that will draw lines. (gldrawline() I think.)
Last edited by jedipenguin; September 13th, 2012 at 11:27 PM.
-
September 14th, 2012, 08:48 PM
#2
Re: Am needing help, perhaps, with an easy, hopefully, OpenGL Assignment.
I've gotten much further along yet am running into a mysterious "external compiler error" as it's an external error being flagged yet my code has no compiler errors.
I'm thinking it's because I didn't "promote" my widget as the promote button somehow wasn't being activated even though it should have been.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|