Direct X really basic help.

This is a discussion on Direct X really basic help. within the Windows Programming forums, part of the Platform Specific Boards category; Ok so I haven't been able to hit this book as much as I wanted to ( Final month or ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Direct X really basic help.

    Ok so I haven't been able to hit this book as much as I wanted to ( Final month or so of high school), I've had to do a lot of stuff the last few weeks. I was doing an example of this book. and I stumble upon this

    Code:
    	//move the ball
    	ptBallPosition.x+=ptBallVelocity.x;
    	ptBallPosition.y+=ptBallVelocity.y;
    
    	//bounds checking
    	//left side
    	if(ptBallPosition.x<=0) ptBallVelocity.x=abs(ptBallVelocity.x);
    	//top side
    	if(ptBallPosition.y<=0) ptBallVelocity.y=abs(ptBallVelocity.y);
    	//right side
    	if(ptBallPosition.x>=(int)dwDisplayWidth-gdicBall.GetWidth()) ptBallVelocity.x=-abs(ptBallVelocity.x);
    	//bottom side
    	if(ptBallPosition.y>=(int)dwDisplayHeight-gdicBall.GetHeight()) ptBallVelocity.y=-abs(ptBallVelocity.y);

    I am not really sure what's going in on here with the bounds checking this "abs" business I dont' really know what that is, could someone please clarify this for me? Thanks.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    abs() returns an absolute value.......negative becomes positive......floating points dissapear..

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Thanks Fordy, this book keeps introducing things assuming that you already know it.........I just realized something I hate Microsoft at times but I also like Windows very much.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Code:
    	ptBallPosition.x+=ptBallVelocity.x;
    	ptBallPosition.y+=ptBallVelocity.y;
    
    	//bounds checking
    	//left side
    	if(ptBallPosition.x<=0) ptBallVelocity.x=abs(ptBallVelocity.x);
    	//top side
    	if(ptBallPosition.y<=0) ptBallVelocity.y=abs(ptBallVelocity.y);
    	//right side
    	if(ptBallPosition.x>=(int)dwDisplayWidth-gdicBall.GetWidth()) ptBallVelocity.x=-abs(ptBallVelocity.x);
    	//bottom side
    	if(ptBallPosition.y>=(int)dwDisplayHeight-gdicBall.GetHeight()) ptBallVelocity.y=-abs(ptBallVelocity.y);
    Could you please give me walk through of this right here.......
    if(ptBallPosition.x<=0) ptBallVelocity.x=abs(ptBallVelocity.x);

    this is what I am thinking........if the X coordinate of the Ball is <=0 then something happens but I don't really know what the velocity has to do with the position of the ball, if you need to see the whole code let me know so I can post it. Thanks in advance.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    E,
    Check out the initialization code. ptBallVelocity.x and .y are each
    preset to hold the value 1. During each loop ptBallPosition is
    updated by ptBallVelocity. So if ptBallVelocity was -3 and
    ptBallPosition's last .x coord was 2 then it would now be -1
    (2+(-3)=-1).

    If the ball (ptBallPosition) has reached the leftmost point of the
    screen (0 or less) then we need to redirect it to the right. To do
    this we get the absolute value of ptBallVelocity (in the case of my
    example here that would be abs(-1)=1). Then we reset the value
    of ptBallVelocity.x to this.
    Code:
    //if ptBallPosition.x is equal to or less than zero
    if(ptBallPosition.x<=0) ptBallVelocity.x=abs(ptBallVelocity.x);
    //if(-1<=0) ptBallVelocity.x=abs(-1);
    //ptBallVelocity=1;
    Now (until we reach the rightmost point of the screen) when we
    incriment ptBallPosition.x by ptBallVelocity.x it will go to the right.
    Code:
    ptBallPosition.x+=ptBallVelocity.x;
    ptBallVelocity.x and .y are just the amount to move the ball
    up/down/left/right each iteration of the loop. Change your init
    code to set them at a higher number and it'll do the same thing,
    just moving the ball faster.

    Hope this helps. If not, PM me.

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Does having a negative on the velocity change the direction on which the ball is moving? Because I figured this would make it go to the opposite side in which the ball is moving if you made it a negative.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by elchulo2002
    Does having a negative on the velocity change the direction on which the ball is moving? Because I figured this would make it go to the opposite side in which the ball is moving if you made it a negative.
    Yup.....I'm working on something based on this principle at the moment.....

    Code:
    rect1.left += lVolX1;//move a rectangle
    rect1.top += lVolY1;
    rect1.right += lVolX1;
    rect1.bottom += lVolY1;
    
    			  
    if(rect1.left <= 0 || rect1.right >= cx)
    	lVolX1 = -lVolX1;
    
    if(rect1.top <= 0 || rect1.bottom >= cy)
    	lVolY1 = -lVolY1;
    Each time this code is run, the rect moves across the screen....if it touches any edge of the screen the number that its being incremented by has its signing swapped...this sends it in the opposite direction........

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 05:28 AM
  3. Direct Input shutting down improperly
    By Deo in forum Game Programming
    Replies: 3
    Last Post: 06-14-2005, 07:54 AM
  4. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM

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