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

This is a discussion on New to direct x, no idea what this means.. within the Game Programming forums, part of the General Programming Boards category; Ok, I saw a code that gives the coordinates to the camera. Here was the code Code: #define CAMERA_X 0.0f ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    16

    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
    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
    Location
    The edge of the known universe
    Posts
    32,845
    The f suffix on a floating point number just tells you that it is a float (the default is double)

    So
    Code:
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    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:
    Code:
    float x = CAMERA_X + 1.0f;
    The compiler would replace that with:
    Code:
    float x = 0.0f + 1.0f;

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    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
    Location
    Sweden
    Posts
    3,145
    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!

    Use
    Code:
    const float CAMERA_X = 12.0f;
    const float CAMERA_Y = 34.0f;
    instead
    MagosX.com

    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, 10: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 Cprogramming.com
    Replies: 9
    Last Post: 08-17-2001, 01:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21