Movies

posted in Beals Software
Published April 25, 2006
Advertisement
Just a quick update. I finished the quad and vertex classes (I'm going to use them in the 3D audio demos) and made a couple movies. They both are exactly the same, except one has a black background and the other has a green background (I would have just switch in the middle, but there isn't any sort of scripting or anything available.)

View this first
And this second

As you can see this uses my visiblity function to only show a certain amount of the whole quad (in this case, the 64x64128x128(forgot I had it stretched) section that the mouse is over.) I have a few ideas on how to incorporate this into my game.

For those that are wondering, this is the heart of the beast:
Vertex* Quad::GetVertices(Texture* pSrcTexture, bool bVisibleUpdate, RECT* pClippingRect){	if(bVisibleUpdate)	{		RECT QuadRect = {m_Position.x, m_Position.y, m_Position.x + m_nWidth, m_Position.y + m_nHeight};		RECT VisibleRect;		IntersectRect(&VisibleRect, pClippingRect, &QuadRect);		float fOffsetX = abs(QuadRect.left - VisibleRect.left);		float fOffsetY = abs(QuadRect.top - VisibleRect.top);		D3DXVECTOR2	Position;		float		fWidth, fHeight;		RECT		SrcRect;		Position.x	= m_Position.x + fOffsetX;		Position.y	= m_Position.y + fOffsetY;		fWidth		= VisibleRect.right - VisibleRect.left;		fHeight		= VisibleRect.bottom - VisibleRect.top;		SrcRect.left	= m_SrcRect0.left + fOffsetX;		SrcRect.top		= m_SrcRect0.top + fOffsetY;		SrcRect.right	= SrcRect.left + fWidth;		SrcRect.bottom	= SrcRect.top + fHeight;		m_Vertices[0].SetXY(Position.x, Position.y + fHeight);		m_Vertices[1].SetXY(Position.x, Position.y);		m_Vertices[2].SetXY(Position.x + fWidth, Position.y);		m_Vertices[3].SetXY(Position.x, Position.y + fHeight);		m_Vertices[4].SetXY(Position.x + fWidth, Position.y);		m_Vertices[5].SetXY(Position.x + fWidth, Position.y + fHeight);		m_Vertices[0].SetColor(m_nTint);		m_Vertices[1].SetColor(m_nTint);		m_Vertices[2].SetColor(m_nTint);		m_Vertices[3].SetColor(m_nTint);		m_Vertices[4].SetColor(m_nTint);		m_Vertices[5].SetColor(m_nTint);		float fLeft		= (float)SrcRect.left / (float)pSrcTexture->GetWidth();		float fTop		= (float)SrcRect.top / (float)pSrcTexture->GetHeight();		float fRight	= (float)SrcRect.right / (float)pSrcTexture->GetWidth();		float fBottom	= (float)SrcRect.bottom / (float)pSrcTexture->GetHeight();		m_Vertices[0].SetUV(fLeft, fBottom);		m_Vertices[1].SetUV(fLeft, fTop);		m_Vertices[2].SetUV(fRight, fTop);		m_Vertices[3].SetUV(fLeft, fBottom);		m_Vertices[4].SetUV(fRight, fTop);		m_Vertices[5].SetUV(fRight, fBottom);		return (Vertex*)m_Vertices;	}	if(m_bDirtyPosition)	{		m_Vertices[0].SetXY(m_Position.x, m_Position.y + m_nHeight);		m_Vertices[1].SetXY(m_Position.x, m_Position.y);		m_Vertices[2].SetXY(m_Position.x + m_nWidth, m_Position.y);		m_Vertices[3].SetXY(m_Position.x, m_Position.y + m_nHeight);		m_Vertices[4].SetXY(m_Position.x + m_nWidth, m_Position.y);		m_Vertices[5].SetXY(m_Position.x + m_nWidth, m_Position.y + m_nHeight);	}	if(m_bDirtyTint)	{		m_Vertices[0].SetColor(m_nTint);		m_Vertices[1].SetColor(m_nTint);		m_Vertices[2].SetColor(m_nTint);		m_Vertices[3].SetColor(m_nTint);		m_Vertices[4].SetColor(m_nTint);		m_Vertices[5].SetColor(m_nTint);	}	if(m_bDirtySource0)	{		float fLeft		= (float)m_SrcRect0.left / (float)pSrcTexture->GetWidth();		float fTop		= (float)m_SrcRect0.top / (float)pSrcTexture->GetHeight();		float fRight	= (float)m_SrcRect0.right / (float)pSrcTexture->GetWidth();		float fBottom	= (float)m_SrcRect0.bottom / (float)pSrcTexture->GetHeight();		m_Vertices[0].SetUV(fLeft, fBottom);		m_Vertices[1].SetUV(fLeft, fTop);		m_Vertices[2].SetUV(fRight, fTop);		m_Vertices[3].SetUV(fLeft, fBottom);		m_Vertices[4].SetUV(fRight, fTop);		m_Vertices[5].SetUV(fRight, fBottom);	}	m_bDirtyPosition	= false;	m_bDirtySize		= false;	m_bDirtyTint		= false;	m_bDirtySource0		= false;	return (Vertex*)m_Vertices;}


This isn't the fastest method, but I'm not worried about that right now (it runs, and it doesn't lag the system at all, so I'm sticking with it.)

Next up will be a movie with sound and a moving thingy.
Previous Entry Untitled
Next Entry Update
0 likes 3 comments

Comments

HopeDagger
Cool beans. [smile]

You're journal has really gone up a few more notches since I last was reading it. Your progress seems to be great! I'm particularly interested in the RPG-ish game you've got in development down there. I'll be sure to keep a keener eye on your journal.
April 25, 2006 07:43 PM
Programmer16
Thanks! Hopefully I can keep up with development on it and EDI Project2, because if not my RPG will have to wait =/.

Speaking of which, your game is coming along nicelyyour game looks freaking awesome! I've been watching your updates and it looks like its going to be hella fun =D. Keep up the good work =D.

Edit: I especially like the nail bomb.
April 25, 2006 07:59 PM
Programmer16
I figured I'd post the demo code, instead of the engine code. Here it is in all its glory:

class MyFramework : public dftFramework
{
	dft::TextureManager	m_TexManager;
	dft::Texture*		m_pVisibleTestTex;
	dft::Texture*		m_pFlashlightTex;
	dft::Quad		m_VisibleTestQuad;
	dft::Quad		m_FlashlightQuad;
public:
	bool Setup()
	{
		m_pVisibleTestTex	= m_TexManager.GetResource("visibletest.bmp");
		m_pFlashlightTex	= m_TexManager.GetResource("flashlight.png");

		m_VisibleTestQuad.Move(0.0f, 0.0f);
		m_VisibleTestQuad.Resize(512, 512);
		m_VisibleTestQuad.SetTint(dft::Color::White);
		m_VisibleTestQuad.SetSrcRect(0, 0, 512, 512);

		m_FlashlightQuad.Move(0.0f, 0.0f);
		m_FlashlightQuad.Resize(128, 128);
		m_FlashlightQuad.SetTint(dft::Color::White);
		m_FlashlightQuad.SetSrcRect(0, 0, 64, 64);

		m_Graphics.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		m_Graphics.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		m_Graphics.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
		return true;
	}

	void Shutdown(){}

	void InputEventHandler(const dft::InputEvent& Event)
	{
		if(Event.m_nMessage == dft::IM_KEYDOWN && Event.m_ucKey == dft::IK_ESCAPE)
			PostQuitMessage(0);
	}

	bool Frame()
	{
		m_FlashlightQuad.MoveRel(m_Input.GetRelMousePos().x, m_Input.GetRelMousePos().y);

		RECT ClippingRect;
		ClippingRect.left	= m_Input.GetAbsMousePos().x;
		ClippingRect.top	= m_Input.GetAbsMousePos().y;
		ClippingRect.right	= ClippingRect.left + 128;
		ClippingRect.bottom	= ClippingRect.top + 128;

		IDirect3DVertexBuffer9* pBuffer = 0;
		m_Graphics.GetDeviceComPtr()->CreateVertexBuffer(dft::Vertex::SIZE * 12, 0, dft::Vertex::FVF, D3DPOOL_MANAGED, &pBuffer, 0);

		dft::Vertex* pVertices = 0;
		pBuffer->Lock(0, 0, (void**)&pVertices, 0);

		// The GetVertices() function takes 3 arguments, the last 2 have default values.
		// GetVertuices(Texture/*for source rect*/, DoVisibilityTest = false, ClippingRectPointer = 0).
		memcpy(pVertices, m_VisibleTestQuad.GetVertices(m_pVisibleTestTex, true, &ClippingRect), dft::Vertex::SIZE * 6);
		memcpy(&pVertices[6], m_FlashlightQuad.GetVertices(m_pFlashlightTex, false), dft::Vertex::SIZE * 6);
		pBuffer->Unlock();

		m_Graphics.GetDeviceComPtr()->SetStreamSource(0, pBuffer, 0, dft::Vertex::SIZE);
		m_Graphics.SetFVF(dft::Vertex::FVF);
		m_Graphics.SetTexture(0, m_pVisibleTestTex);
		m_Graphics.GetDeviceComPtr()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
		m_Graphics.SetTexture(0, m_pFlashlightTex);
		m_Graphics.GetDeviceComPtr()->DrawPrimitive(D3DPT_TRIANGLELIST, 6, 2);

		pBuffer->Release();
		return true;
	}
};






The GetVertices() function updates the vertices and returns them. I have 4 dirty variables:
bool m_bDirtyPosition; // o_O
bool m_bDirtySize;
bool m_bDirtyTint;
bool m_bDirtySource0;
If GetVertices() second argument is false, the function only updates the those that are dirty. If it is true, all 4 are updated (no matter what.) Only the vertices are modified either way.
April 25, 2006 09:43 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement