Never-ending DirectX Thread... menu

User Tag List

Results 1 to 6 of 6
  1. #1
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Never-ending DirectX Thread...

    So, I've read just about all of the DX threads I could get my hands on. There's a lot of crappy code out there, and I had to piece together what to do.

    I've got the game rendering basic indexed primitives in game at game coordinates, but I'm having two problems.

    First, it appears that I'm having significant problems when the D3D device gets reset for any reason. That's my guess, but it seems to happen on resize or changing from windowed/full screen. I'm not sure how I'm "supposed" to be detecting and handling this case.

    Second, I suspect that my matrices are still a bit off. I had to sort of cobble them together from bits and pieces that I found here. The reason that I suspect my matrices are off is that my rendered primitive sort of... slides around on the ground. Not by much, but in the two ss's I'm attaching, you can clearly see that with just a different camera position, the rendered pyramid seems to "slide" from to the gnome's right to the gnome's left. I suspect it's something subtle or simple, since it's not flying around the screen all crazy-like (it's... MOSTLY stable on-screen).

    So, let me expose myself to ridicule by dumping my code. Don't mock me too much, it's just a work-in-progress. I'll clean it up once I get it really "working"...

    Code:
    typedef float idVec3[3];
    typedef float idMat3[3][3];
    
    #pragma pack(1)
    typedef struct _CSimpleCamera
    {
    public:
    	// 0x0 -- vftable
        virtual float GetFov( );
        virtual idVec3& Forward( idVec3& vecOut );
        virtual idVec3& Right( idVec3& vecOut );
        virtual idVec3& Up( idVec3& vecOut );
    		
        /* 0x04 */ char unknown4[4];
        /* 0x08 */ idVec3 vecPosition;
        /* 0x14 */ float matFacing[3][3];
        /* 0x18 */ float Fov;
    } CSimpleCamera, *PCSimpleCamera;
    
    struct CUSTOMVERTEX
    {
    	float x, y, z;
    	DWORD color;
    };
    
    #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)
    LPDIRECT3DVERTEXBUFFER9 vb = 0;
    IDirect3DIndexBuffer9* ib = 0;
    #define TRIANGLE_SIZE 1.0f
    
    void DrawCrap(IDirect3DDevice9* pDevice, float posX, float posY, float posZ)
    {
    	CSimpleCamera *cam = GetCamera();
    
    	if (cam)
    	{
    		// Capture the current state before we mess with it
    		if (!stateBlock)
    		{
    			pDevice->CreateStateBlock(D3DSBT_ALL, &stateBlock);
    			stateBlock->Capture();
    		}	
    
    		D3DXVECTOR3 pos(posX, posY, posZ); // location in the game world where object should appear
    		D3DXMATRIX world, view, proj;
    		
    		D3DXVECTOR3 vEyePt( cam->vecPosition[0], cam->vecPosition[1], cam->vecPosition[2] );
    		D3DXVECTOR3 vLookatPt( cam->vecPosition[0]+cam->matFacing[0][0], cam->vecPosition[1]+cam->matFacing[0][1], cam->vecPosition[2]+cam->matFacing[0][2] );
    		D3DXVECTOR3 vUpVec( 0.0f, 0.0f, 1.0f );
    
    		D3DXMatrixLookAtRH(&view,
    			&vEyePt,
    			&vLookatPt,
    			&vUpVec);
    
    		D3DXMatrixPerspectiveFovRH(&proj, cam->Fov*0.6f, 1920.0f/1200.0f, 0.1f, 1000000.0f/* 0.92f */);
    			
    		// needed to render at all
    		pDevice->SetVertexShader(NULL);
    		pDevice->SetPixelShader(NULL);
    				
    		pDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
    		pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
    		pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    
    		// Prevent Blizzard from setting the alpha of our polygons on mouseover
    		pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    		pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    		pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    
    		if (!vb)
    		{
    			HRESULT hr = pDevice->CreateVertexBuffer(5 * sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &vb, NULL);
    			CUSTOMVERTEX* pVertices;
    			vb->Lock( 0, 0, (void**)&pVertices, 0 );
    
    			pVertices[0].x=-TRIANGLE_SIZE;
    			pVertices[0].y=-TRIANGLE_SIZE;
    			pVertices[0].z=TRIANGLE_SIZE;
    			pVertices[0].color = D3DCOLOR_ARGB(255, 255, 0, 0);
    			pVertices[1].x=0.0f;
    			pVertices[1].y=0.0f;
    			pVertices[1].z=-TRIANGLE_SIZE;
    			pVertices[1].color = D3DCOLOR_ARGB(255, 0, 255, 0);
    			pVertices[2].x=TRIANGLE_SIZE;
    			pVertices[2].y=-TRIANGLE_SIZE;
    			pVertices[2].z=TRIANGLE_SIZE;
    			pVertices[2].color = D3DCOLOR_ARGB(255, 0, 0, 255);
    			pVertices[3].x=TRIANGLE_SIZE;
    			pVertices[3].y=TRIANGLE_SIZE;
    			pVertices[3].z=TRIANGLE_SIZE;
    			pVertices[3].color = D3DCOLOR_ARGB(255, 0, 255, 0);
    			pVertices[4].x=-TRIANGLE_SIZE;
    			pVertices[4].y=TRIANGLE_SIZE;
    			pVertices[4].z=TRIANGLE_SIZE;
    			pVertices[4].color = D3DCOLOR_ARGB(255, 255, 0, 0);
    			vb->Unlock();
    
    			hr = pDevice->CreateIndexBuffer(6*3*2, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED,  &ib, NULL);
    			WORD *indices=NULL;
    			ib->Lock( 0, 0, (void**)&indices, 0 );
    			indices[0]=0;
    			indices[1]=1;
    			indices[2]=2;
    			indices[3]=2;
    			indices[4]=1;
    			indices[5]=3;
    			indices[6]=3;
    			indices[7]=1;
    			indices[8]=4;
    			indices[9]=4;
    			indices[10]=1;
    			indices[11]=0;
    			indices[12]=0;
    			indices[13]=2;
    			indices[14]=4;
    			indices[15]=4;
    			indices[16]=2;
    			indices[17]=3;
    			ib->Unlock();
    		}
    
    		D3DXMatrixTranslation(&world, pos.x, pos.y, pos.z);
    		pDevice->SetTransform(D3DTS_WORLD, &world);
    		pDevice->SetTransform(D3DTS_VIEW, &view);
    		pDevice->SetTransform(D3DTS_PROJECTION, &proj);
    		
    		pDevice->SetTexture(0, NULL);
    		pDevice->SetStreamSource(0, vb, 0, sizeof(CUSTOMVERTEX));
    		pDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
    		pDevice->SetIndices(ib);
    		pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,5,0,6);  
    
    		if (stateBlock)
    			stateBlock->Apply();
    	}
    }
    I just need to solve the "sliding solid" issue, and I'm good to go... Now if only I could get the zbuffer stuff working so I could draw primitives at the right LEVEL... but when I tried adding in the zbuffer stuff, all KINDS of weird things started happening.





    ---------- Post added at 06:59 PM ---------- Previous post was at 06:32 PM ----------

    So I checked a couple of other threads, and my up vector is right (when I change it from 0,0,1 to 0,1,0 everything goes nutso). As far as I know, my fov is right (the value in the float I'm accessing is PI/2, and I'm multiplying that by 0.6, as per some other threads, although I'd love to know WHY...). My aspect ratio is hard-coded at 1920/1200.

    The only thing I'm not 100% sure of is my "at" vector. The calculation of taking the vector of the cam position and basically just treating the first row of the M33 in the camera structure as a row vector seems a bit... sketchy to me. I've seen example code where the "at" vector is the result of the cam pos + the M33, but as far as I know, you can't simply add a 3x3 matrix and a vector3...

    I have a nasty ass headache from the cold I'm fighting, and this crap is making it worse... grr...

    ---------- Post added at 07:58 PM ---------- Previous post was at 06:59 PM ----------

    Hmm, looking at it closer, I'm not sure it's actually wrong. I think that the lack of zbuffering (or something!) is just making it LOOK wrong.

    When I zoom over the pyramid looking straight down, everything looks rock solid. It's just that when I'm rotating around it at an oblique angle like this, the fact that it's not correctly drawn "behind" some things and "in front of" others makes it screw with your sense of position.

    I'm not sure how to fix that.

    ---------- Post added at 08:02 PM ---------- Previous post was at 07:58 PM ----------

    Hmm, a little more complicated than that. When I zoom the camera all the way in to first-person, the "sliding" problem goes away. It's still annoyingly not-3D, but it's not slithering away when I rotate my view. It has something to do with the camera's position not being the same as the character's position.

    ---------- Post added at 08:07 PM ---------- Previous post was at 08:02 PM ----------

    Duh, figured it out. My "up" vector isn't automatically just 0,0,1, because as I rotate the camera to point down, the "up" vector for the camera tilts. When I changed the "up" vector to fetch from the camera instead of hard-coding it, the annoying "sliding" stopped. Now I just have to figure out how to render the solid so that it appears to be in the correct z-depth. Right now, it occludes EVERYTHING, the UI, gameobjects, everything.
    Last edited by amadmonk; 03-08-2011 at 07:17 PM.
    Don't believe everything you think.

    Never-ending DirectX Thread...
  2. #2
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind, I've pretty much solved all of my DirectX issues except for what the correct sequence is to render the same indexed primitive 10 times in 10 different locations. If someone wants to help with THAT, I'd be obliged.

    Now that I have a good way of visualizing pathfinding points, I'll return back to working on local steering/navigation.
    Don't believe everything you think.

  3. #3
    reggggg's Avatar Member
    Reputation
    1
    Join Date
    Sep 2009
    Posts
    22
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should write a blog

  4. #4
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by amadmonk View Post
    Never mind, I've pretty much solved all of my DirectX issues except for what the correct sequence is to render the same indexed primitive 10 times in 10 different locations. If someone wants to help with THAT, I'd be obliged.

    Now that I have a good way of visualizing pathfinding points, I'll return back to working on local steering/navigation.
    MSDN discusses doing that using shaders if you wanted to do that. See http://msdn.microsoft.com/en-us/libr...49(VS.85).aspx

  5. #5
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, I figured out my problem. I was rendering a list of primitives, but I wasn't checking to see if some of them were behind the view plane, and at least one was. It didn't have anything to do with rendering the primitive multiple times, after all.

    Sorry for all the spam (and, ha ha reggggg), but all this DX stuff is COMPLETELY new to me. Bot AI and behavior, no problem. Pixel shaders? WTF is THAT??

    And thanks for the tip adaephon; I may try that in the future since it seems like a much more efficient way to draw the same primitive in multiple locations/orientations/colors.

    Edit: hmmm, that's not it. I've rendered primitives behind the camera before. It's definitely trapping when I call the SetTransform's, however...
    Last edited by amadmonk; 03-09-2011 at 01:40 PM.
    Don't believe everything you think.

  6. #6
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, figured it out. Duh. It had absolutely NOTHING to do with where I was rendering the primitive in WoW-space. I was calling the function that triggered the rendering from a keystroke, which means that I was attempting to do the rendering outside of EndScene. I am going to put in some bumpers now to make sure I can't make THAT mistake again...
    Don't believe everything you think.

Similar Threads

  1. [Useless][Druid][Engineer only(?)] Never ending Far Sight
    By Klime in forum World of Warcraft Exploits
    Replies: 11
    Last Post: 09-01-2008, 07:50 PM
  2. The never ending story
    By the hunter of the hunted in forum Community Chat
    Replies: 1
    Last Post: 08-04-2008, 08:35 AM
  3. Get xp fast at lvl 40 ish, never ending supply
    By gibberish in forum World of Warcraft Exploits
    Replies: 19
    Last Post: 03-06-2008, 05:28 PM
  4. never ending nature swiftness
    By km3r in forum World of Warcraft Exploits
    Replies: 20
    Last Post: 05-18-2007, 11:10 AM
  5. Never ending beer
    By Datonking in forum World of Warcraft Exploits
    Replies: 6
    Last Post: 09-15-2006, 05:27 PM
All times are GMT -5. The time now is 04:51 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search