R4v3nh34rt

Member

5

102 Neutral

• Rank
Newbie
1. 3D Movement

Okay, maybe I'm mistaken but what are you exactly hoping to achieve with that? Why are you both adding and subtracting the same quantity to the same variable each frame? That way that particular cell will always contain the same value at the end of the loop. If you didn't mean to post both increment and decrement and you just wanted to point out what you wanted to achieve, then it should work just fine on the y axis. Why are you using different indexes? 5 for the increment and 1 for setting the position back to 0? In other words, that's basically what Trienco also said. It is just not clear why you're doing this. Why don't you keep either the increment or the decrement and also explain why you're using two different indexes for the array... I don't seem to grasp that
2. How to access classes properly?

Basically, I'm making an engine with the following classes: Point Line Rectangle Solid (parent) - Cube (subclass) Entity Now, it works like this: Entity->Cube->Rectangle->Line->Point a solid needs faces that are made of rectangles, which are made of lines, which are made of two points. This seemed as a fairly nice way to handle things as I can easily handle , change, manage, edit, set every part of a cube. Rotation, motion etc are all based on points and every function goes up to the solids. So every point "influences" what is going on in their upper level. I got a problem with this approach though: 1) is this a nice / convenient / efficient way to do it? 2) if not, what would be a better way to handle things given my necessity of handling each aspect of the solid independently ? 3) I made a constructor for entity and every other class that look like this: Entity::Entity(GLfloat size) { body = new CubeSolid(1.0,false,false); spawned = false; } CubeSolid::CubeSolid(GLfloat size,bool hidden, bool wireMode) : PrimitiveSolid() { faces[0] = new Rectshape(1.0,false); faces[1] = new Rectshape(1.0,false); faces[2] = new Rectshape(1.0,false); faces[3] = new Rectshape(1.0,false); faces[4] = new Rectshape(1.0,false); faces[5] = new Rectshape(1.0,false); //// IRRELEVANT CODE //// } Rectshape::Rectshape(GLfloat size,bool hidden) { this->_topside = new Line(size,false); this->_rightside = new Line(size,false); this->_bottomside = new Line(size,false); this->_leftside = new Line(size,false); //// IRRELEVANT CODE //// } Line::Line(GLfloat size, bool hidden) { point1 = new Point(1.0,1.0,1.0,true); point2 = new Point(1.0,1.0,1.0,true); //// IRRELEVANT CODE //// } Point::Point(GLfloat x, GLfloat y, GLfloat z,bool hidden) { pos[0] = x; pos[1] = y; pos[2] = z; oPos[0]=x;oPos[1]=y;oPos[2]; visible = !hidden; } With this approach I can easily create an entity and the constructors will do the rest since I have a function that automatically arranges points, rectangles, lines in a solid shape, no matter how far apart or how they're located in the space. I can access the solid class from Entity, has body is a solid object. But in order to access the rectangles that make up the solid, I need to do that thru the cube class directly! But I get uninitialized member variables and crashes when i call member functions that go beyond the solid class ( like rectangles). For example, if I have the Entity class with body inside it, body is a pointer to a solid object (a cube in this case). Though I can easily access the solid from a pointer to entity, I cannot seem to access the rectangles of which body is made of. I cannot seem to do this: entityList[0]->body->faces[0]->function(); So how would I solve this problem? PS: the "this" pointer is there because I copy pasted from another constructor in the same class. The code is not complete because the issue doesn't seem to be in the source code itself, the problem is in the way I 'm trying to access the classes as It works just fine by defining every point, line, rectangle and then pass all those objects to the "default" constructor I made for the class. I just want to make this other way work because it is more convenient to me. The info I provided should be enough in order to address and solve the issue, hopefully.
3. [C++] Application crashes

Sorry, I missed the global declaration when I pasted. Thanks for giving multiple answers. here's the global declaration: Entity* entityList[MAX_ENTITIES]; So unfortunatly it fits into your "C" answer, damn it . It's really weird as it seems to work outside the function "createEntity" with the exact same code, but once inside the function it just crashes the program. This is odd.I also traced the error and it's definetly that assignment that causes it.