Thread: Modelling OpenGL class

  1. #1
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152

    Modelling OpenGL class

    Hi there! This is a simple question, which I do not know how to answer. I am making a simple OpenGL game, and I have a class called Scene. This class has many coordinates and attributes. What do you think it is better:

    1) Create a function that receive, as a parameter, the Scene class and ask for its attributes.

    2) A public method Scene::draw().

    I am asking this because I do not think that is good to have OpenGL function calls inside the Scene class, it makes the class less generic.
    One solution could be create a second class, like a wrapper, that has one Scene and a draw method.

    Thanks any opinion.

  2. #2
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Posts
    121
    If your architecture is going to revolve around OpenGL there's nothing wrong with having opengl calls inside a class.

    If you don't want OpenGL called all over the shop, and you would rather have a generic renderer that contains all the calls to OpenGL, then do that instead! Create a set of helper classes that wrap the rendering, and use those from your generic classes.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    You could create some kind of SceneDrawIterator class that iterates the nodes in the scene by drawing order.

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Actually you can make a circle in text mode, albeit it will be limited by the resolution of the cells you are using. Just pick a center point. Comput how many angles are in one cell of text. This is can be done by computing the distance from top left of cell to bottom right. Use that as the angle increment and use cos() and sin() through 90 degrees.

    Top=angle
    Right=angle+90
    Bottom=angle+180
    Left=angle+270

    These four sections will make a circle.

  5. #5
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    Thank all replyies! I will use wrapper classes, so I can change the core of the game with little redesign if needed.

    I have one more question about modeling. I have a Ship that will fly through the Scene. I must check for collisions. What would be best?

    1) Scene receive a Ship as a parameter and checks if the Ship collides against its elements.

    2) Ship receive a Scene as a parameter.

    3) A function that receives both as a parameter.

    I would use the third option, but it will introduce a C style function, instead of reinforce OO.

    The first option will reduce flexibility.

    Again, thanks any opinion!

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Your ship (and anyother collide-able object) should have some sort of bounding volume. Your bounding volume class should have the functionality to test for collisions (or more accurately, intersections) with other bounding volumes.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    I would use the third option, but it will introduce a C style function, instead of reinforce OO.
    Global functions can be just as OO has any other technique. They're useful when you want to capture a common way of accessing a class. #2 of your choice can be immediately eliminated because ship isn't responsible for checking collisions. #1, creating another class, and #3 are the only possible alternatives. #1 can be eliminated if your scene is only responsible for only storing objects, not detecting whether objects collide.

  8. #8
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    I will take the third option, thank you all!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help on class coupling
    By andrea72 in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2011, 10:16 AM
  2. calling OpenGL methods from outside the main class
    By Hector in forum Game Programming
    Replies: 2
    Last Post: 06-22-2006, 07:23 AM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM