Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 620555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:46:36+00:00 2026-05-13T18:46:36+00:00

I’m writing a simple scene graph to hold some objects so I can control

  • 0

I’m writing a simple scene graph to hold some objects so I can control the rendering and drawing of these objects in OpenGL. I have two classes, one called GameObject which defines the objects with certain parameters such as position and velocity as well as how to draw the object. It has a method called update() which is used to calculate any change in position and then calls the draw() to draw itself onto the screen.

Another class is called sceneNode. This class controls the data structure which I use to store the objects. This an instance of this class contains a pointer to a GameObject instance to allow me to access the data and a sceneNode has children of type sceneNode stored in a vector.

Each class works perfectly well on their own. I can add children to the scene graph etc and I can create a GameObject and tell it to draw itself and everything works as expected.

I then added a new method to sceneNode which is called render(), this method gets the pointer to gameObject and calls it’s update function before calling render() on any children of the node.

The problem is: the update() method is called and the GameObject is drawn but it is always drawn in the same place and doesn’t move despite having a velocity and change in position. Calling the update() function by using an instance of GameObject DOES draw the object and move the object around the screen. I’ve been staring at this code for hours and can’t see what I’m missing. I’m still fairly new to the idea of pointers and calling methods from another class so I may have missed something obvious.

Here are the relevant methods:

GameObject.cpp:
The variables position, velocity etc are listed as protected.

void GameObject::update(){

for (int i = 0; i<3;i++){
    this->velocity[i] +=this->acceleration[i];  
}
this->position[0] += this->velocity[0];
this->position[1] += this->velocity[1];
this->position[2] += this->velocity[2];

this->draw();
}


void GameObject::draw() {
glTranslatef(this->position[0], this->position[1], this->position[2]);

glBegin(GL_TRIANGLES);
for (int i = 0; i < this->num_tris; i++) {
    for (int j = 0; j <3 ; j++) {
        glVertex3fv(vertices[triangles[i].INDEXES[j]]);
    }
}
glEnd();
}

sceneNode.cpp:

void sceneNode::render(){
GameObject *go = new GameObject();
go = this->data;
//data is the name of the variable storing a pointer to a GameObject
go->update();   
//update() is a method that redraws the object and calc's new position etc

if (hasChildren()) {    //if this node has children, render all of them aswell...
    for (int i = 0; i< this->node_tree.size(); i++) {
        this->node_tree.at(i).render();             
    }
}

sceneNode.h:
This is how the GameObject pointer is set up in the sceneNode

Protected:
GameObject* data;

I’m lost as to why the position is not changing for the render() method but is for the update() method as they are both calling the same thing?

Thanks for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:46:37+00:00Added an answer on May 13, 2026 at 6:46 pm

    There are some big problems here.

    GameObject *go = new GameObject();
    go = this->data;
    

    You’re creating a new object and then you are forgetting the pointer to that object. This happens every time you call render, so you have tons of memory that you aren’t using that grows with time. You can just say:

    GameObject *go = NULL;
    

    to create a pointer without allocating data to it.

    You can also omit the this->foo everywhere. It’s implied within all classes.

    So although I can’t see the error in this code, chances are it is elsewhere, since you’re making mistakes with pointers like above. You probably have pointers pointing to things you’re not drawing. If you look at the memory addresses of the things that are updating and the memory addresses of the things being updated in render(), they may actually be different. If they are then you know that you’re not calling update on the same things you are drawing. To get a memory address look at the value of ‘this’ within a function call. Write them down and make sure they are the same as the objects you are drawing. The error is not in this code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.