Thread: New to direct x, no idea what this means..

  1. #1
    Registered User
    Join Date
    Jan 2005

    Unhappy New to direct x, no idea what this means..

    Ok, I saw a code that gives the coordinates to the camera. Here was the code
    #define CAMERA_X 0.0f
    #define CAMERA_Y 4.0f
    #define CAMERA_Z 7.0f
    this I would guess is a type of measurement, I dont know what it's using to place it. What does f mean? what does the entire number 4.0f mean? I dont get it, and theres nothing that explains it. This is one of the many things hendering me from getting through my book.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    The f suffix on a floating point number just tells you that it is a float (the default is double)

    float a = 1.23f;
    double b = 1.23;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Those are preprocesser directives which tell the compiler to go throughout the source code, and replace all instances of CAMERA_X with 0.0f, CAMERA_Y with 4.0f, and CAMERA_Z with 7.0f. The f at the end of the number means the type is a float, not a double.

    So if in your code you see:
    float x = CAMERA_X + 1.0f;
    The compiler would replace that with:
    float x = 0.0f + 1.0f;

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    But I don't recommend hard-coding camera x,y,z values into the code. Ultimately you want a class to encapsulate a 3D camera and all its properties.

    In DirectX those camera coords will place your camera at:

    0 units off of the Y axis on the X axis.
    4 units below the X axis on the Y axis.
    7 units into the screen on the z axis.

    In DirectX you normally have this setup.

    X is negative as you move left and positive as you move right
    Y is negative as you move up and positive as you move down
    Z is negative TOWARDS the camera and positive AWAY FROM the camera or INTO the screen.
    Last edited by VirtualAce; 01-20-2005 at 12:50 AM.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Even if you do want to hardcode the camera position, DON'T use #define. Use a constant instead. Defines are generally bad since:

    No type checking!
    Can replace other parts of the code if you're not careful!

    const float CAMERA_X = 12.0f;
    const float CAMERA_Y = 34.0f;

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A little problem about an idea, help please
    By louis_mine in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2004, 09:52 PM
  2. Terrain engine idea
    By VirtualAce in forum Game Programming
    Replies: 15
    Last Post: 04-03-2004, 01:30 AM
  3. number guessing game, no idea where to start
    By karin in forum C Programming
    Replies: 9
    Last Post: 03-18-2004, 09:49 PM
  4. New idea on conveting byte to bits/bits to byte
    By megablue in forum C Programming
    Replies: 10
    Last Post: 10-26-2003, 01:16 AM
  5. totally screwed up idea
    By iain in forum A Brief History of
    Replies: 9
    Last Post: 08-17-2001, 12:09 PM