Jump to content
  • Advertisement

R4v3nh34rt

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

102 Neutral

About R4v3nh34rt

  • Rank
    Newbie
  1. R4v3nh34rt

    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. 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. R4v3nh34rt

    [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.
  4. Greetings everyone, I just joined the community and hopefully asking a question right-away as my first post won't appear rude. I'll get straight to the point: I'm new at C++ programming , I actually started programming with the latter. I had grasped the basics of programming with C++ , but of course, I hadn't learnt nor mastered the complexity of the language as it takes years to do that as I'm sure many of you experienced programmers know. Then I sticked with other , easier languages because I thought they were the most appropriate to my needs: Python, pawn, some little games in assembly just to challenge myself. After all of this, the result is that when reverting back to C++, the difficulties when it came to making some things work were just unexplainable to me. For instance, I made this program using the opengl libraries, it's going to be a game. I'm basically making a little engine from scratch just to make a simple game out of it, it's not going to be a lifetime project, but merely a practicing project. So any unrelated tips regarding the style of programming I've adopted should be avoided, as I'm sure we'll be able to discuss that at a later time. The main problem with my program is that when I create the object inside a function and then assign the object to an array, it crashes the program. The following is the main part of the code, If i'm not mistaken it's the only one that really counts in order to solve the issue: Entity* entityList[MAX_ENTITIES]; Entity* createEntity() { Point p1(2.0,1.0,-2.0,true); Point p2(2.5,1.0,-2.0,true); Point p3(2.5,1.5,-2.0,true); Point p4(2.0,1.5,-2.0,true); Line l1(p1,p2,false); Line l2(p2,p3,true); Line l3(p3,p4,true); Line l4(p4,p1,true); Rectshape r1(l1,l2,l3,l4,false); Point p5(1.0,1.0,-2.0,true); Point p6(1.5,1.0,-2.0,true); Point p7(1.5,1.5,-2.0,true); Point p8(1.0,1.5,-2.0,true); Line l5(p5,p6,true); Line l6(p6,p7,true); Line l7(p7,p8,true); Line l8(p8,p5,true); Rectshape r2(l5,l6,l7,l8,false); Point p9(3.0,1.0,-2.0); Point p10(3.5,1.0,-2.0); Point p11(3.5,1.5,-2.0); Point p12(3.0,1.5,-2.0); Line l9(p9,p10,true); Line l10(p10,p11,true); Line l11(p11,p12,true); Line l12(p12,p9,true); Rectshape r3(l9,l10,l11,l12,false); Point p13(3.0,1.0,-2.0,true); Point p14(3.5,1.0,-2.0,true); Point p15(3.5,1.5,-2.0,true); Point p16(3.0,1.5,-2.0,true); Line l13(p13,p14,true); Line l14(p14,p15,true); Line l15(p15,p16,true); Line l16(p16,p13,true); Rectshape r4(l13,l14,l15,l16,false); Point p17(3.0,1.0,-2.0,true); Point p18(3.5,1.0,-2.0,true); Point p19(3.5,1.5,-2.0,true); Point p20(3.0,1.5,-2.0,true); Line l17(p17,p18,true); Line l18(p18,p19,true); Line l19(p19,p20,true); Line l20(p20,p17,true); Rectshape r5(l17,l18,l19,l20,false); Point p21(13.0,1.0,-2.0,true); Point p22(13.5,1.0,-2.0,true); Point p23(13.5,1.5,-2.0,true); Point p24(13.0,1.5,-2.0,true); Line l21(p21,p22,true); Line l22(p22,p23,true); Line l23(p23,p24,true); Line l24(p24,p21,true); Rectshape r6(l21,l22,l23,l24,false); CubeSolid *c1 = new CubeSolid(r1,r2,r3,r4,r5,r6,true,true); Entity *e1; e1 = new Entity(*c1,ENTITY_DYNAMIC_TYPE); return e1; } int main (int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(HEIGHT, WIDTH); glutInitWindowPosition(100, 50); glViewport(0, 0, WIDTH, HEIGHT); glGetIntegerv(GL_VIEWPORT,viewport); glGetDoublev(GL_MODELVIEW_MATRIX,modelview); glGetDoublev(GL_PROJECTION_MATRIX,projection); glutCreateWindow("Mofo"); init(); glutDisplayFunc(display); glutPassiveMotionFunc(getMousePosition); glEnable(GL_DEPTH_TEST); glClearColor(1.0,1.0,1.0,0.0); entityList[0]=createEntity();// CRASHES THE PROGRAM for (int e = 0; e < 1; e++) { if (entityList[e]) { entityList[e]->spawn(true); if (entityList[e]->type == ENTITY_DYNAMIC_TYPE) { int threadIndex = getIdleThreadIndex(); if (threadIndex > -1) { //HANDLE threadHandles[threadIndex] = e threadExecuted[threadIndex] = 1; threadDelay[threadIndex] = 50; threadedEntities[threadIndex] = entityList[e]; threadedFunctions[threadIndex] = FUNC_MOVETO; CreateThread(NULL, 0, gameThread, &threadIndex, 0, NULL); } } } } glutIdleFunc(idle); glutMainLoop(); } For some reason it doesn't happen when I don't use the createEntity function, and just put everything in main. The following code works: int main (int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(HEIGHT, WIDTH); glutInitWindowPosition(100, 50); glViewport(0, 0, WIDTH, HEIGHT); glGetIntegerv(GL_VIEWPORT,viewport); glGetDoublev(GL_MODELVIEW_MATRIX,modelview); glGetDoublev(GL_PROJECTION_MATRIX,projection); glutCreateWindow("Mofo"); init(); glutDisplayFunc(display); glutPassiveMotionFunc(getMousePosition); glEnable(GL_DEPTH_TEST); glClearColor(1.0,1.0,1.0,0.0); Point p1(2.0,1.0,-2.0,true); Point p2(2.5,1.0,-2.0,true); Point p3(2.5,1.5,-2.0,true); Point p4(2.0,1.5,-2.0,true); Line l1(p1,p2,false); Line l2(p2,p3,true); Line l3(p3,p4,true); Line l4(p4,p1,true); Rectshape r1(l1,l2,l3,l4,false); Point p5(1.0,1.0,-2.0,true); Point p6(1.5,1.0,-2.0,true); Point p7(1.5,1.5,-2.0,true); Point p8(1.0,1.5,-2.0,true); Line l5(p5,p6,true); Line l6(p6,p7,true); Line l7(p7,p8,true); Line l8(p8,p5,true); Rectshape r2(l5,l6,l7,l8,false); Point p9(3.0,1.0,-2.0); Point p10(3.5,1.0,-2.0); Point p11(3.5,1.5,-2.0); Point p12(3.0,1.5,-2.0); Line l9(p9,p10,true); Line l10(p10,p11,true); Line l11(p11,p12,true); Line l12(p12,p9,true); Rectshape r3(l9,l10,l11,l12,false); Point p13(3.0,1.0,-2.0,true); Point p14(3.5,1.0,-2.0,true); Point p15(3.5,1.5,-2.0,true); Point p16(3.0,1.5,-2.0,true); Line l13(p13,p14,true); Line l14(p14,p15,true); Line l15(p15,p16,true); Line l16(p16,p13,true); Rectshape r4(l13,l14,l15,l16,false); Point p17(3.0,1.0,-2.0,true); Point p18(3.5,1.0,-2.0,true); Point p19(3.5,1.5,-2.0,true); Point p20(3.0,1.5,-2.0,true); Line l17(p17,p18,true); Line l18(p18,p19,true); Line l19(p19,p20,true); Line l20(p20,p17,true); Rectshape r5(l17,l18,l19,l20,false); Point p21(13.0,1.0,-2.0,true); Point p22(13.5,1.0,-2.0,true); Point p23(13.5,1.5,-2.0,true); Point p24(13.0,1.5,-2.0,true); Line l21(p21,p22,true); Line l22(p22,p23,true); Line l23(p23,p24,true); Line l24(p24,p21,true); Rectshape r6(l21,l22,l23,l24,false); CubeSolid *c1 = new CubeSolid(r1,r2,r3,r4,r5,r6,true,true); Entity *e1; e1 = new Entity(*c1,ENTITY_DYNAMIC_TYPE); entityList[0]=e1; for (int e = 0; e < 1; e++) { if (entityList[e]) { entityList[e]->spawn(true); if (entityList[e]->type == ENTITY_DYNAMIC_TYPE) { int threadIndex = getIdleThreadIndex(); if (threadIndex > -1) { //HANDLE threadHandles[threadIndex] = e threadExecuted[threadIndex] = 1; threadDelay[threadIndex] = 50; threadedEntities[threadIndex] = entityList[e]; threadedFunctions[threadIndex] = FUNC_MOVETO; CreateThread(NULL, 0, gameThread, &threadIndex, 0, NULL); } } } } glutIdleFunc(idle); glutMainLoop(); } Ignore the thread cycle and other stuff which is unrelated to the issue, I tested it. Thanks for your help, time and attention .
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!