Thread: i've basically stopped game programming

  1. #16
    Registered User
    Join Date
    Mar 2004
    Posts
    13
    The point of a singleton is that, whenever you make you try to make a new instance of it, you get the first created instance(unless no previous one has been created). SO if you're singleton has say a variable for Time since program started(just a random example), so then it can be accessed everytime by simply creating a pointer of the singleton.

    SingletonTime *Time = new SingletonTime();
    Time.SetTime(GetTickCount());

    thats in your main or winmain function, now all your other functions, objects etc. can go

    Code:
    void submain() {
    SingletonTime *Time = new SingletonTime()l
    cout << Time.getTime();
    }
    and it will print out your time you set in the main function, it works really well, and does allow really complicated systems.

  2. #17
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I know how singletons work. And like I said, they're neat, but they're never absolutely necessary. Also, I don't know if you realize this or not, but your code isn't valid, because in a singleton class the constructor is made to be private...otherwise it isn't a singleton (you're allocating a new singleton in main, which is illegal to do because you cannot access the constructor, which is called when you invoke new). The actual object is a class data member, and subsequently resides only in the .h file of the class definition (you have to include that .h file in order to get the actual object).

    All of that is, in my opinion, a pain in the ass

    EDIT:
    has anyone actually downloaded my presentation? It's pretty basic and not totally interesting if you already have a good bearing in 3D

  3. #18
    Registered User
    Join Date
    Mar 2004
    Posts
    13
    I'm fully aware my code would not actually work that way, I do know the constructors are private(I think I said it in my previous post as well), I was just being lazy . I was also just trying to be helpful, I know some people who found it to be very much so, I wasn't trying to be mean or anything

  4. #19
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    All of that is, in my opinion, a pain in the ass
    Agreed.

    I wasn't trying to be mean or anything
    We know you weren't and no one said you were. It's just that as of late a great many of us have been talking about the more we get into C++ the more we dislike it because of certain major design problems it presents. IMHO Microsoft's COM and COM +, ActiveX, and/or now .NET is a much better object oriented approach than C++. Not to say that C++ does not have a lot of power or anything or is useless, but it is not easy to code large complex systems because you run into 'now this class needs to know about this class, but I don't wanna derive from this
    class..so.......' All that does is confuse the crapola outta ya.

    I actually tried to make a complete game in C++ and lemme tell ya by the time I actually got down to creating the game elements, there were so many inheritance issues and data protection issues that it was even confusing just trying to create a sprite object. Because a sprite is a bitmap either moving or stationary, and a sprite is a bitmap, and the bitmap should be able to draw itself which means it needs access to video, which is another class, blah, blah, blah. It was hideous.

    class VideoSystem {};
    class Bitmap:public VideoSystem {};
    class BaseSprite:public VideoSystem, public Bitmap {};
    class MovingSprite:public BaseSprite {};
    class NonMovingSprite:public BaseSprite {};
    class AnimatedSprite:public BaseSprite {};
    class MovingAnimatedSprite:public AnimatedSprite {};
    class NonMovingAnimatedSprite:public AnimatedSprite {};
    class TileMap:public VideoSystem, public Bitmap {};
    .....
    ...


    You get the idea. A huge mess.
    Last edited by VirtualAce; 03-08-2004 at 04:44 PM.

  5. #20
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I do have a question - how do I project my vertices to screen space via a projection matrix? Currently all my rotations, scaling, translations, and transformations are done via matrices but my projection is done separately. I would like to do it via a matrix.


    I know the projection matrix is this:

    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 1/D 0

    But can I use this concatenate function with it and if I can then where are the screen coords at in the final matrix??
    Code:
    void MatMult(double m1[4][4],double m2[4][4],double r[4][4])
    }
      for (int i=0;i<4;i++)
      {
        for (int j=0;j<4;j++)
        {
          for (int k=0;k<4;k++)     
          {
            r[i][j]+=m1[i][k]*m2[k][j];
           }
         }
      }
    }
    I know I can unroll the inner loop but I didn't cuz the huge line of code would not fit well in this window.

    And here is my Viewtransform code:
    Code:
    //Transforms world vertexes to view vertexes
    void ViewTransform(vertex *vtxs,int numvtxs)
    {
      for (int i=0;i<numvtxs;i++)
      {
         double x=vtxs[i].world.x;
         double y=vtxs[i].world.y;
         double z=vtxs[i].world.z;
         
         double vx=x*matrix[0][0]+y*matrix[0][1]+z*matrix[0][2]+matrix[0][3];
         double vy=y*matrix[1][0]+y*matrix[1][1]+z*matrix[1][2]+matrix[1][3];
         double vz=z*matrix[2][0]+y*matrix[2][1]+z*matrix[2][2]+matrix[2][3];
         
         vtxs[i].view.x=vx;
         vtxs[i].view.y=vy;
         vtxs[i].view.z=vz;
       }
    }
    Then my project function:
    Code:
    void Project(vertex *vtxs, int numvtxs,double vdist,int cx,int cy)
    {
      for (int i=0;i<numvtxs;i++)
      {
         double vx=vtxs[i].view.x;
         double vy=vtxs[i].view.y;
         double vz=vtxs[i].view.z;
     
         double sx=vx*vdist/vz+cx;
         double sy=vy*vdist/vz+cy;
        
         vtxs[i].screen.x=sx;
         vtxs[i].screen.y=sy;
       }
    }
    But I want to project via the projection matrix using my concatenate or MatMult() function if possible. Note, I know DirectX and OpenGL do this for you but I want to know whats going on underneath it all - this is from my small DOS 3D engine written in DJGPP or 32-bit C.
    Last edited by VirtualAce; 03-08-2004 at 05:12 PM.

  6. #21
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I wasn't trying to be mean or anything
    its cool buddy, I wasn't being defensive. To be honest, I was just being honest

    Bubba, I know how to project vertices against the viewing plane, but I don't know what the equivalent matrix looks like to be honest, sorry. Just for your info, I've never written a software rasterizer like you have, subsequently I'm a bad resource for things like that (chances are if OpenGL takes care of it, I haven't worried about it too much)

    EDIT:
    hmm, I posted that without actually reading your project function. I don't know if you *can* directly turn those equations into a matrix by hand. I believe this because you aren't summing any terms, and matrices always sum terms even for simple things such as polar coordinates. I tried posting something else, but realized it wasn't useful. You'd have to do jumping jacks just to find an equivalent equation. I'd msdn for it, but otherwise I dunno
    Last edited by Silvercord; 03-08-2004 at 07:56 PM.

  7. #22
    Registered User impactBlue's Avatar
    Join Date
    Mar 2004
    Posts
    5
    i just completed a project for my class that pretty much did what you are doing. given 3d points of objects in world reference coordinates; camera coordinates and orientation; and various transformations to be applied to the objects, my program is to render in image in screen coordinates. don't know if this info will help but given all the info i stated, i constructed matrices to peform the standard transformations (shear, rotate, translate, etc...), matrix for view coordinates, matrix for projection & normalized device coordinates, and finally device/screen coordinates. i basically put em all into a single composite matrix; then took all the given 3d points as homogenous coordinates; multiplied it with the composite matrix; homogenized the result (which should be a 4x1 matrix) and the screen coordinates are in (0,0) and (0,1) of the resultant 4x1 matrix. so i don't know if that answers your question to where the screen coordinates are; for my project they were simply in the "x" and "y" elements of the resultant 4x1 matrix (vector). and Yes, you should be able to concatenate all your matrices, from one end of the 3d pipeline to the other. i used a stack. before pushing down each matrix, i multiplied it with the top (this way i can pop down the stack to get to each stage of the 3d pipeline). i just used some general matrices given in a book, if you want them i can post em for you. as for how the projection matrix and normalized device coord matrices are derived, i can't really help you because i'm still trying to understand the mathematics behind it. hope it helps and good luck on the proj!

  8. #23
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    okay, you didn't answer his question. His concise question was 'what *matrix* can you use to project vertices through the screen'. He's already got a method for doing this without a matrix, as do i, but he specifically asked for a matrix.

  9. #24
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The matrix is this:


    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 1/D 0

    where 1/d is distance from screen or:


    screen.x=view.x*Distance/view.z+screencenter.x;
    screen.y=view.y*Distance/view.z+screencenter.y;


    But I want to concatenate the view matrix above into my concatenation pipeline using my 4x4 matrix multiply. However, I do not know where the resultant screen coords would be unless it would be 0,0 and 1,1....which would make sense.

  10. #25
    Registered User
    Join Date
    Mar 2004
    Posts
    13
    I've used .NET and a few others (c#, asp.net, bunches of others), its not really any better, for the most part is worse. True there are some problems in C++, but I've never had any problem creting a large object systems, I thought it was fairly simple, however the nature of object orientated programming is that you will have bunches of objects that all somehow relate to a bunch of other objects, and in turn to more, it gets confusing at times. I always try to get my objects to relate to each other as much as possible, either through inheritance, or how they use each other, and it usually works fine.

    However I do agree that there have been some good advances, that I do hope to see implemented more often in newer languages, and more advances made.

  11. #26
    C++ Learner :D
    Join Date
    Mar 2004
    Posts
    69
    Originally posted by Silvercord
    has anyone actually downloaded my presentation? It's pretty basic and not totally interesting if you already have a good bearing in 3D [/B]
    Yes ive just dloaded it

    its cool, im a complete n00b even to basic c++ so this is way over my head. you guys are amazing!

    i really wanna be able to understand this stuff, but ill just stick with the basics for now! keep up the good work!

    BTW, is it possible to dload and play the games you have made?

  12. #27
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    Hmm, I don't actually have any playable games, I've just basically written a huge 3D engine. I am building a cathedral, and I might add support for alpha blending for glass. I'm working on adding sky, and I'm adding support for various other entities. i can show you that when i'm done with it (I'm building the map as well as updating the rendering engine and some physics and entity parsing, etc).

  13. #28
    C++ Learner :D
    Join Date
    Mar 2004
    Posts
    69
    yeah thatd be cool to see, although ud have to explain to me how to make it run etc.. (unless its just a simple .exe) as im a complete n00b to this...

  14. #29
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    here's a screen

  15. #30
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    Nice sky Silvercord! Is that implemented using a skydome? also, what is with the bit of shearing above the door archway?

    EDIT: What is the list of current features of your engine?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  4. Game Design Topic #1 - AI Behavior
    By TechWins in forum Game Programming
    Replies: 13
    Last Post: 10-11-2002, 10:35 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM