locked
Find the windows bounds in direct3d

    Question

  • How should I find the window bounds in directX. In XNA, we used graphics.GraphicsDevice.ViewPort.Width, but I haven't found anything like that yet for directX. I have previously tried:

    CoreWindow^ Window = CoreWindow::GetForCurrentThread();

    float windowWidth = Window->Bounds.Width;

    Monday, January 13, 2014 8:18 PM

Answers

All replies

  • Your CoreWindow code looks correct. What problem are you having with it?

    Tuesday, January 14, 2014 12:35 AM
    Moderator
  • void CGame::Update()
    {
    	if (BallSpeedX == 0.0f)
    	{
    		BallSpeedX = 4.0f;
    		BallSpeedY = 4.0f;
    	}
    
    	//get window size
    	CoreWindow^ Window = CoreWindow::GetForCurrentThread();
    	//bounce off sides
    	if (BallPosX > Window->Bounds.Width)
    	{
    		BallSpeedX *= -1.0f;
    	}
    	if (BallPosX < -Window->Bounds.Width)
    	{
    		BallSpeedX *= -1.0f;
    	}
    	if (BallPosY > Window->Bounds.Height)
    	{
    		BallSpeedY *= -1.0f;
    	}
    	if (BallPosY < -Window->Bounds.Height)
    	{
    		BallSpeedY *= -1.0f;
    	}
    	Time = 0.02f;
    	BallPosX += BallSpeedX * Time;
    	BallPosY += BallSpeedY * Time;
    }

    It is giving a large number that I can't figure out how it is getting. I am new to directX and was building a pong game to get the hang of it, and the number I got was in the 600-range. It should have been around 15.

    I was trying to get the window boundaries so I could "bounce" the ball off the edges of the screen. I put in some more code if it helps

    Tuesday, January 14, 2014 12:54 AM
  • Why do you expect a Width around 15?

    Windows will always be at least 500 wide (unless you opt in to 320), and generally larger.

    --Rob

    Tuesday, January 14, 2014 2:17 AM
    Moderator
  • When I had replaced the Window->Bounds.Height with a number around 15, It worked right on my screen. I was after that trying to scale it to different screens. It may be that I am looking for the wrong number. The template I was using (from DirectXTutorial.com) seems to prefer normalized device coordinates, rather than screen coordinates.
    Tuesday, January 14, 2014 2:53 PM
  • Yes, you have a scaling issue. The bounds you are getting sounds correct, but you'll need to translate that into your coordinate system.

    --Rob

    Wednesday, January 15, 2014 3:31 AM
    Moderator