Jump to content

  • Log In with Google      Sign In   
  • Create Account

cozzie

Member Since 13 Oct 2004
Online Last Active Today, 02:21 PM

#5273513 Classes and header files mess

Posted by cozzie on 31 January 2016 - 01:29 PM

Hi.

You're question is too big (for me) to cover with just 1 right answer.

So here's my share:

 

- when you have headers that you want to include in several places, 'ifdef' them

(so they're just compiled once)

#ifndef CD3DCAM_H
#define CD3DCAM_H

(top of your headers)

 

- in general a class should have 1 purpose only (like mentioned above)

- when you want to make a 'game engine', think of modules, for example:

-- audio

-- IO

-- rendering

-- scenes/ levels

-- objects

-- meshes ( --- submeshes etc.)

 

You could use a namespace for each 'module'




#5273360 Order of transformation confuse

Posted by cozzie on 30 January 2016 - 10:10 AM

You could draw out both options on paper, where you do the different orders of actions.

This helps in illustrating whap happens (SRT, TSR etc.).

 

Here's a snippet of my 'old' engine code:

void CD3dmeshInst::CreateWorldMatrix()
{
	D3DXMatrixTranslation(&mMatTranslate, mWorldPos.x, mWorldPos.y, mWorldPos.z);
	D3DXMatrixRotationX(&mMatRotateX, D3DXToRadian(mRot.x));
	D3DXMatrixRotationY(&mMatRotateY, D3DXToRadian(mRot.y));
	D3DXMatrixRotationZ(&mMatRotateZ, D3DXToRadian(mRot.z));
	D3DXMatrixScaling(&mMatScale, mScale, mScale, mScale);

	mMatWorld = (D3DXMATRIXA16)(mMatScale*mMatRotateX*mMatRotateY*mMatRotateZ*mMatTranslate);

	D3DXMatrixInverse(&mMatWorldInv, NULL, &mMatWorld);
	D3DXMatrixTranspose(&mMatWorldInvTransp, &mMatWorldInv);
}

I believe it shouldn't matter if you're using OpenGL or Direct3D (not 100% sure though, if not, someone will correct me :))




#5271909 Collision using rgb

Posted by cozzie on 19 January 2016 - 05:13 PM

Besides the perfect approach Alberth suggested, you could do AABB /sphere collision detection, this comes to pixel perfect and gives you future possibilities to expand into a 3rd dimension (height). If you want to move on to 3d later, it's also good practice to understand this sort of collisions (and expand them later to 3d).

Speaking from expierence (www.crealysm.com, games, BooH).


#5271402 Vertex to cube using geometry shader

Posted by cozzie on 16 January 2016 - 08:22 AM

For who's interested, here's the result.

I can now switch between the 14 and 24 vertices versions.

 

geocube_14vtx.jpg

 

geocube_24vtx.jpg

 

The geometry shader (relevant parts):

	// texture coordinates for the geometry shader cube: using 1 big strip, 14 vertices
	float2 gTexCStrip[14] = 
	{
		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f),
		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),
		float2(0.0f, 0.0f),
		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f),
		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f),
		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),
		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),
		float2(1.0f, 0.0f),
	};

	// tex coords for 6 quad version of geometry shader cube
	float2 gTexC[24] = 
	{
		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f),
		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),

		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f),
		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),

		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),
		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f),

		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),
		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f),

		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f),
		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),

		float2(0.0f, 0.0f),
		float2(1.0f, 0.0f),
		float2(0.0f, 1.0f),
		float2(1.0f, 1.0f)
	};

	float3 gNormalsStrip[14] =
	{
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),

		float3(1.0f, 0.0f,  0.0f),
		float3(1.0f, 0.0f,  0.0f),
		float3(1.0f, 0.0f,  0.0f),

		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),

		float3(0.0f, 0.0f,  1.0f),
		float3(0.0f, 0.0f,  1.0f),
		float3(0.0f, 0.0f,  1.0f)
	};

	float3 gNormals[24] =
	{
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),

		float3(1.0f, 0.0f,  0.0f),
		float3(1.0f, 0.0f,  0.0f),
		float3(1.0f, 0.0f,  0.0f),
		float3(1.0f, 0.0f,  0.0f),

		float3(0.0f, 0.0f,  1.0f),
		float3(0.0f, 0.0f,  1.0f),
		float3(0.0f, 0.0f,  1.0f),
		float3(0.0f, 0.0f,  1.0f),

		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),

		float3(0.0f, 1.0f,  0.0f),
		float3(0.0f, 1.0f,  0.0f),
		float3(0.0f, 1.0f,  0.0f),
		float3(0.0f, 1.0f,  0.0f),

		float3(0.0f, -1.0f,  0.0f),
		float3(0.0f, -1.0f,  0.0f),
		float3(0.0f, -1.0f,  0.0f),
		float3(0.0f, -1.0f,  0.0f)
	};

[maxvertexcount(24)]
void GSBoxQuads(point VertexOut gin[1], 
        uint primID : SV_PrimitiveID, 
        inout TriangleStream<GeoOut> triStream)
{	
	// calculate halfWidth and height to create cube vertices			==> ONLY USING SIZE X!
	float halfWidth		= 0.5f*gin[0].SizeW.x;
	float halfHeight	= 0.5f*gin[0].SizeW.x;
	float halfDepth		= 0.5f*gin[0].SizeW.x;
	
	// create the 24 vertices of the cube
	float4 boxv[24];
	boxv[0] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[1] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[2] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[3] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[4] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[5] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[6] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[7] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[8] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[9] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[10] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[11] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[12] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[13] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[14] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[15] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[16] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[17] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[18] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[19] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[20] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[21] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[22] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[23] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);

	// indices 6 quads * 4 vertices
	int index[24] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
	
	// after each quad, restart the strip
	GeoOut gout;
	[unroll]
	for(int q1=1;q1<25;++q1)
	{
		gout.PosH     = mul(boxv[index[q1-1]], gViewProj);
		gout.PosW     = boxv[index[q1-1]].xyz;
		gout.NormalW  = gNormals[index[q1-1]];
		gout.Tex      = gTexC[index[q1-1]];
		gout.PrimID   = primID;
		
		triStream.Append(gout);

		if(q1 % 4 == 0) triStream.RestartStrip();
	}
}


[maxvertexcount(14)]
void GSBoxStrip(point VertexOut gin[1], 
        uint primID : SV_PrimitiveID, 
        inout TriangleStream<GeoOut> triStream)
{	
	// calculate halfWidth and height to create cube vertices			==> ONLY USING SIZE X!
	float halfWidth		= 0.5f*gin[0].SizeW.x;
	float halfHeight	= 0.5f*gin[0].SizeW.x;
	float halfDepth		= 0.5f*gin[0].SizeW.x;
	
	// create the 8 vertices of the cube
	float4 boxv[14];
	boxv[0] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[1] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[2] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[3] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[4] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[5] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[6] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[7] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[8] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[9] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[10] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[11] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[12] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[13] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);

	int index[14] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

	GeoOut gout;
	[unroll]
	for(int i=0;i<14;++i)
	{
		gout.PosH     = mul(boxv[index[i]], gViewProj);
		gout.PosW     = boxv[index[i]].xyz;
		gout.NormalW  = gNormalsStrip[index[i]];
		gout.Tex      = gTexCStrip[index[i]];
		gout.PrimID   = primID;
		
		triStream.Append(gout);
	}
}




#5271109 Vertex to cube using geometry shader

Posted by cozzie on 14 January 2016 - 01:42 PM

The bithackery is a bridge too far for me :)

Thanks all, I agree that isn't the 'ideal' situation to achieve what I'm doing, but I'm just trying out Geometry shaders, to understand them.

 

I thought I had it, but I didn't or just broke it.

While trying to fix it, I think I've found a problem with the approach, some vertices are shared in faces, which causes a problem with the normals.

Resulting in 'half a cube' being visible.

Here's the code and the result:

	float3 gNormals[14] =
	{
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),
		float3(0.0f, 0.0f, -1.0f),

		float3(1.0f, 0.0f,  0.0f),
		float3(1.0f, 0.0f,  0.0f),
		float3(1.0f, 0.0f,  0.0f),

		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),
		float3(-1.0f, 0.0f,  0.0f),

		float3(0.0f, 0.0f,  1.0f),
		float3(0.0f, 0.0f,  1.0f),
		float3(0.0f, 0.0f,  1.0f)
	};

	float4 boxv[14];
	boxv[0] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[1] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[2] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[3] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[4] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[5] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[6] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[7] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[8] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[9] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	-halfDepth, 1.0f);
	boxv[10] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[11] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	-halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[12] = float4(gin[0].CenterW.x	-halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);
	boxv[13] = float4(gin[0].CenterW.x	+halfWidth, gin[0].CenterW.y	+halfHeight, gin[0].CenterW.z	+halfDepth, 1.0f);

	int index[14] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

	GeoOut gout;
	[unroll]
	for(int i=0;i<14;++i)
	{
		gout.PosH     = mul(boxv[index[i]], gViewProj);
		gout.PosW     = boxv[index[i]].xyz;
		gout.NormalW  = gNormals[index[i]];
		gout.Tex      = gTexC[index[i]];
		gout.PrimID   = primID;
		
		triStream.Append(gout);
	}

geom_cube_NOK1.jpg

geom_cube_NOK2.jpg

 

I might be able to fix it, by adding additional vertices and coming to 6 faces * 4 vertices = 24 vertices.

Any other ideas?




#5270912 Should I use an engine or hard code with libraries?

Posted by cozzie on 13 January 2016 - 01:20 PM

Hi.
I believe it depends on what you eventually want to achieve, combined with what you like to do most. If you want to make fun games, an engine will do. If you want to fully learn rendering, low level API usage, creating your own framework etc., then you could start creating your own engine. The 2nd option is nice but has a strong learning curve, takes lots of discipline and time.


#5270745 (UE4) Let players choose between graphic settings, how does it work?

Posted by cozzie on 12 January 2016 - 02:25 PM

Hi.
Welcome.

I think you're going a bit to quick. A 3d scene/ world consists of different 3d objects. You can either create or download them (for example in the unity store). A 3d engine, like UE4 can render your world, using a lot of different techniques and special effects. Depending on what effects you use, you might need better/ faster hardware. In the basis, the 3d world you create doesn't have to be different depending on how "high quality" you want to render it.

Based on your question (no offense), you might want to start with some basic tutorials or a book. Learning the basic principles of the magic world of 3d rendering and games ;)


#5270659 Good Choices for a first game?

Posted by cozzie on 12 January 2016 - 04:08 AM

My share;
Asteroids, Pacman


#5268005 The Best Ideas for a first game?

Posted by cozzie on 26 December 2015 - 04:42 AM

Asteroidz or Pacman might be a good start, despite the correct movement to the other forum :)

Here's an example on a GDD of a 'simple'/ clone game, you might even go for a simpler approach:

http://www.crealysm.com/downloads/documents/booh-game-design-final.pdf




#5267124 Which side is better?

Posted by cozzie on 20 December 2015 - 04:02 AM

It depends on what you're trying to achieve eventually/ aka what your goal is.


#5267123 How do you organize your time for game dev?

Posted by cozzie on 20 December 2015 - 04:00 AM

Work from a plan, define milestones and small deliverables.
Finishing deliverables lets you both keep track and give you motiviation for the next one. Finishing stuff is like a drug :)

What are you planning to make?


#5267121 I have no experience AT ALL

Posted by cozzie on 20 December 2015 - 03:44 AM

First of all, welcome!
I also advice to get a free legal version of visual studio community (2013 or 2015).

When it comes to learning C++, you could start with something basic like input/ output, writing to a ASCII file and reading back, maybe something like a basic calculator. Google is your friend for C++ beginner tutorials.

Watch you that you wont become one of many that think you can build a MMORPG with no expierence, team etc.

When you're getting the hang of it, pick an API (like direct3d 11) and first finish basic games, making and actually finishing a full clone of pacman, asteroids or Pong could be your first big milestone.

After that, you can define your next steps. Good luck


#5266556 Paying someone to work on a "mod"?+ "games that started as "m...

Posted by cozzie on 15 December 2015 - 03:40 PM

I think the payment itself is no issue.
It's what you're planning with the mod after it's finished, that you might have to check legally


#5266325 A Good Game Engine?

Posted by cozzie on 14 December 2015 - 01:36 PM

N.p., good luck on gaining your first experience.

You might consider doing some 'clone' games to start with, asteroidz and/or pacman are 'relatively doable'




#5266270 A Good Game Engine?

Posted by cozzie on 14 December 2015 - 08:19 AM

I believe it all starts with defining your goal. What do you want to achieve?

With this you can go and solve the "how", which engine, framework, alone vs a team etc




PARTNERS