Gary the Llama

Members
  • Content count

    82
  • Joined

  • Last visited

Community Reputation

134 Neutral

About Gary the Llama

  • Rank
    Member
  1. [C++/DirectX] Strange Access Violation error...

    Quote:Original post by EasilyConfused You're calling QPC correctly, so that is unlikely to be the offender. The error you are getting is from something in your program trying to access memory you don't own, and I'd say given the address, you are trying to dereference a null pointer. What gives you the impression that that line is the problem? Does the debugger seem to point there? I see nothing in your QPC line that could trigger a memory access exception. When the exception occurs, it's stopped at that line of code. I noticed today that it only happens when I enable my collision detection code so it could be a problem there. I'm going to look further into the collision detection code and see what I can find.
  2. My main game loop randomly gives me this error message: Unhandled exception at 0x00000000 in Program.exe: 0xC0000005: Access violation reading location 0x00000000. void GameLoop(HWND hWnd) { __int64 currTime = 0; QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&currTime)); float delta = (currTime - prevTime) * secsPerTick; float timePassed = currTime - prevTime; // GetInput(); Update(delta, hWnd); Render(delta); prevTime = currTime; } This seems to be the offending line: QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&currTime));
  3. Tetris Collision Detection

    I'm working on a Tetris clone... My board is stored in a 2D array (8x20) and I set each position to a value if it is empty or solid. Easy enough. A couple questions though... 1. If the user presses the spacebar, I want the block to drop instantly. How can I only check for the nearest solid block on the column I'm on? 2. When the user moves left or right, it moves the block in 32-pixel chunks, making it pretty easy to test for collisions. But when the block moves down by itself, it's using delta time for smooth movement. I'm having difficulty testing for collisions this way. If it's moving too fast, as in later levels, it will sometimes completely miss the collision and end up stopping halfway through a block. Any ideas?
  4. [C++/DirectX] Problems rendering D3DXSPRITES...

    I think I figured it out. (Or, at least, the program is working as expected now.) [source code="c"] D3DXMatrixTransformation2D(&spriteMatrix, 0, 0, &scaling, 0, 0, &pos); I assume I needed to reset the D3DXMatrixTransformation2D() since pos changed. Is this right? I feel like I'm doing things the wrong way... Once I'm rendering a bunch of sprites, I'll be resetting the matrix a lot, right? What am I doing wrong? Edit: It seems like I remember seeing D3DXSPRITE code that didn't even use the 2D transformation but I tried removing it from my code and it stops working. Should I be using it or no?
  5. I'm trying to render two sprites... One of them, the player's cursor, is controlled by the mouse. That sprite follows the mouse, no problem. I also have a corner sprite that doesn't move. With this code, it also follows the mouse around the screen, even though it never changes position. The render function: void Render() { // Start rendering on the backbuffer. if (d3ddev->BeginScene()) { // Black background d3ddev->ColorFill(backBuffer, NULL, D3DCOLOR_XRGB(0, 0, 0)); sprite->Begin(D3DXSPRITE_ALPHABLEND); D3DXVECTOR2 pos; pos.x = redHand.pos.x; pos.y = redHand.pos.y; D3DXVECTOR2 scaling(1.0f, 1.0f); D3DXMATRIX spriteMatrix; D3DXMatrixTransformation2D(&spriteMatrix, 0, 0, &scaling, 0, 0, &pos); sprite->SetTransform(&spriteMatrix); RECT srcRect; srcRect.left = 0; srcRect.right = 32; srcRect.top = 0; srcRect.bottom = 32; sprite->Draw(playerTexture, &srcRect, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255)); srcRect.left = 0; srcRect.right = 200; srcRect.top = 0; srcRect.bottom = 200; sprite->Draw(cornerTexture, &srcRect, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255)); sprite->End(); d3ddev->EndScene(); } // Flip back buffer to the screen d3ddev->Present(NULL, NULL, NULL, NULL); } The update function: void Update(float delta, HWND hWnd) { PollMouse(); // Move the hand sprite. redHand.pos.x += MouseX(); if (redHand.pos.x > WINDOW_WIDTH - redHand.width) { redHand.pos.x = WINDOW_WIDTH - redHand.width; } else if (redHand.pos.x < 0) { redHand.pos.x = 0; } redHand.pos.y += MouseY(); if (redHand.pos.y > WINDOW_HEIGHT - redHand.height) { redHand.pos.y = WINDOW_HEIGHT - redHand.height; } else if (redHand.pos.y < 0) { redHand.pos.y = 0; } // Check for escape key to exit. if (KEY_DOWN(VK_ESCAPE)) { gameIsRunning = false; } } As you can see, the Update function never changes the position of the corner sprite. Any ideas why it would be following my mouse around along with the cursor sprite?
  6. Camera implementation when doing 2D in Direct3D.

    Quote:Original post by EasilyConfused Personally, I don't use a camera as such for 2D games. I have a pair of floats representing the position of the top left corner of the screen in world co-ordinates, then I subtract that value from the position of everything I render (in simple terms. Obviously for drawing tilemaps and so on, I only render the objects that are visible). I guess you could use a D3D transform rather than subtracting the values yourself, but then you have to render everything regardless of whether it is on the screen or not. Interesting. Can't you do some sort of frustrum culling to not render what's on screen? Thanks for the tip!
  7. A few weeks ago I made a post regarding moving a 3D camera in my 2D world. (This is for a 2D game being made in Direct3D.) Read the original post here. The last post in that thread I was told that I shouldn't be using a 3D camera in my 2D world. So how should I do it? Why should I not use a 3D camera? How would I implement a fake camera if I'm not going to use a 3D camera. I'd love a solution to my problem. Any code snippets or examples would be great. Edit: It seems to me that I should use a 3D camera if it's already available to me.
  8. Moving the camera in my 2D scene...

    Quote:Original post by freeworld Quote:Original post by Gary the Llama Okay so my FVF has D3DFVF_XYZRHW in it and I think that's causing a problem. Is this what's causing my view matrix not to work? yes, that format assumes that there is no need to translate from model space to world space or any transformation like that, everything is based off of screen coordinates. Your idea of using a 3D camera in a 2D world in my opinion is a waste of time. Care to elaborate why you think it's a waste of time? How would you do it?
  9. Moving the camera in my 2D scene...

    Okay so my FVF has D3DFVF_XYZRHW in it and I think that's causing a problem. Is this what's causing my view matrix not to work?
  10. Moving the camera in my 2D scene...

    Mods, if you think it's a good idea, can we move this to the DirectX forum please?
  11. Moving the camera in my 2D scene...

    Anyone? I'd love some help on this...
  12. Moving the camera in my 2D scene...

    Getting closer (I think), but still no camera movement. if (d3ddev->BeginScene()) { // Black background d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0, 0, 0)); // I assume this is where I need to setup a D3DXMATRIX // and then do a d3ddev->SetTransform(D3DTS_VIEW, &out) // but I have no idea what vectors to pass in... // Right now my view is set to identity, my projection // is set to D3DXMatrixOrthoLH(&Ortho2D, 800.0, 600.0, 0.0f, 1.0f); // if it makes a difference... sprite->Begin(D3DXSPRITE_ALPHABLEND); D3DXVECTOR2 pos; pos.x = zamboniSprite.x; pos.y = zamboniSprite.y; RECT srcRect; srcRect.left = 1; srcRect.right = 32; srcRect.top = 1; srcRect.bottom = 32; D3DXVECTOR2 scaling(1.0f, 1.0f); D3DXMATRIX spriteMatrix; D3DXMatrixTransformation2D(&spriteMatrix, 0, 0, &scaling, 0, 0, &pos); //D3DXMatrixTransformation2D(&spriteMatrix, 0, 0, &scaling, 0, 0, &D3DXVECTOR2(150.0f, 150.0f)); sprite->SetTransform(&spriteMatrix); sprite->Draw(spriteTexture, &srcRect, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255)); sprite->End(); d3ddev->EndScene(); I've included comments where I believe I would do my d3ddev->SetTransform(D3DTS_VIEW, &out) but I'm not 100% for sure on that and I have no idea what to pass into the matrix to get the camera moving. Sorry for being so dumb, any help would be appreciated.
  13. Moving the camera in my 2D scene...

    Unfortunately, I'm still lost as to how to do this... Any other suggestions?
  14. Moving the camera in my 2D scene...

    I've got my 2D scene setup using Direct3D 9. I'm using an orthographic view. I've got my sprite displaying on screen. The question is, how do I move the camera in the x and y directions? Here's a snippet from my game loop: if (d3ddev->BeginScene()) { // Black background d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0, 0, 0)); sprite->Begin(D3DXSPRITE_ALPHABLEND); D3DXVECTOR3 pos; pos.x = 10.0f; pos.y = 20.0f; pos.z = 0.0f; RECT srcRect; srcRect.left = 1; srcRect.right = 32; srcRect.top = 1; srcRect.bottom = 32; sprite->Draw(spriteTexture, &srcRect, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); sprite->End(); d3ddev->EndScene(); } d3ddev->Present(NULL, NULL, NULL, NULL); I'm not trying to do anything fancy right now... Just display a sprite and move the camera. I've got no camera movement code in there right now... So how would I have it automatically scroll right? Beforehand, in my Direct3D init code, I'm doing this, if it makes a difference. D3DXMatrixOrthoLH(&Ortho2D, 800.0, 600.0, 0.0f, 1.0f); D3DXMatrixIdentity(&Identity); d3ddev->SetTransform(D3DTS_PROJECTION, &Ortho2D); d3ddev->SetTransform(D3DTS_WORLD, &Identity); d3ddev->SetTransform(D3DTS_VIEW, &Identity); So how can I get that camera moving? :) [Edited by - Gary the Llama on September 18, 2007 8:50:31 PM]
  15. Should my 2D engine use ID3DXSPRITE for tiles?

    Thanks Steve. Right as you replied, I edited my previous post with another question... Mind taking a look at that one too?