Jump to content

  • Log In with Google      Sign In   
  • Create Account


Waaayoff

Member Since 11 Sep 2009
Offline Last Active Today, 07:16 AM
-----

#5150755 What's the best way to handle game objects and their assets in a statical...

Posted by Waaayoff on 01 May 2014 - 10:39 AM


* How to choose which class to make an instance of based on the object type name in the level layout file?

 

There are many ways to do this. First you should separate the graphical representation from the actual object. (i.e you could have four race car objects, but only one mesh that is used for all cars.) Your layout file will contain, among other things, the type of object and an identifier for the mesh(es) it uses.

 

Second you need to choose a paradigm to represent your objects, such as inheritance or Component Entity Systems. Simple inheritance would probably be best for now.

 

Now, when you load your files, you would create an object (naturally you would need if statements like you said but as things get more complicated you will look into more sophisticated patterns such as a factory method). Then you would request the mesh for this object by ID and load it if it wasn't loaded before.

 


* How to load and unload the graphics used by the objects in the layout?

 

Just like you request a mesh to be loaded, you request for it to be deleted. Mesh creation/deletion/requests can be handled by one or more classes. But for now a simple ResourceLoader class would suffice. This class would have for every mesh some kind of counter that counts how many objects are using that mesh. Every deletion request would decrement the counter until it's zero. Here you can either completely delete the mesh or keep it in cache. This depends on the type of game you're making.

 


* It's necessary for objects to find out about other objects of certain types for them to be able to interact.

 

No, they don't. Objects should NOT care about other objects. The game logic and game objects should be separated. For example, if you want to do collision between two objects, you would calculate whatever collision response you want in a different class, then tell each object to change their state or position accordingly. Direct communication between game objects should be minimal if not nonexistent.




#5142669 Proper exporting collada

Posted by Waaayoff on 27 March 2014 - 01:47 PM

I usually export to FBX from Blender (since its Collada exporter is crap), use FBX Converter to convert to Collada, then import using Assimp.




#5142666 Why are my two classes sharing variables? C++

Posted by Waaayoff on 27 March 2014 - 01:23 PM

Just curious. You set a lot of class variables as private. Any reason why you do that?

 

wat  




#5141467 Assimp Skeleton Bind Pose

Posted by Waaayoff on 23 March 2014 - 10:18 AM


Waaayoff, on 23 Mar 2014 - 10:51 AM, said:

// DO NOT FORGET TO TRANSPOSE when you load them
 
So I have to transpose the offset matrix to get the bind pose ?

 

No. From what i remember, this comment was there to remind me to transpose the offset matrix because of the difference between the matrix order between Assimp and DX. Try it with and without transposing and see which one is correct.

 

 

 



Waaayoff, on 23 Mar 2014 - 10:51 AM, said:

D3DXMATRIX final = pJoint->mAnimatedTransf * P;
 
Is 'P' the parent's transform matrix ?

 

Yes. This is the whole function. It will be called with the skeleton's Root bone and an identity matrix.

//=====================================================================================================
// Recursively calculate the joints' combined transformations
//=====================================================================================================
void AnimationController::CombineTransforms(Joint* pJoint, const D3DXMATRIX& P)
{
	  D3DXMATRIX final = pJoint->mAnimatedTransf  *  P;

	  mFinalTransforms.push_back( pJoint->mOffsetTransf * final );

	  for (unsigned i = 0; i < pJoint->mChildren.size(); i++)
	  {
			 CombineTransforms(pJoint->mChildren[i], final);
	  }

Where, like i mentioned above, pJoint->mAnimatedTransf should contain the local transformation if you want to get the bind pose.




#5141388 Assimp Skeleton Bind Pose

Posted by Waaayoff on 23 March 2014 - 03:51 AM

It's been a long time since i looked at my animation code but i found this comment:

 

"Turns out Assimp generates animations relative to the parent joint, NOT the joint itself. So i don't have to multiply the animation transformation by the local transformation. Which i only use if there is no animation for a bone.."

 

Along with this code: (It's used for animation rather than getting the bind pose but since the bind pose is usually the first frame of animation, it should be similar to what you're looking for)

// pJoint->mAnimatedTransf is initialized with Assimp's local transform (which you can find like this: g_Scene->mRootNode->FindNode(bone_name)->mTransformation)
	// Then it can be replaced per frame by an interpolated animation transformation for every bone that has an animation
	// pJoint->mOffsetTransf you can find in an aiBone struct
	// DO NOT FORGET TO TRANSPOSE when you load them

	D3DXMATRIX final = pJoint->mAnimatedTransf  *  P;

 	//mFinalTransforms contains the matrices that will be sent to the shader
	mFinalTransforms.push_back( pJoint->mOffsetTransf * final );

From Assimp's documentation:  "Its [bone's] offset matrix declares the transformation needed to transform from mesh space to the local space of this bone."

 

i.e. it's the inverse bind pose.




#5140342 Your one stop shop for the cause of all coding horrors

Posted by Waaayoff on 19 March 2014 - 10:16 AM

I enjoyed this - thanks for sharing.
 
Also:

// somedev1 -  6/7/02 Adding temporary tracking of Login screen
// somedev2 -  5/22/07 Temporary my ass
The history of software development in a nutshell.

 

 

When I was just programming for fun, i saw that thread and laughed. Oh how i laughed. Now that i'm getting paid to maintain someone else's code... :(




#5111232 Yiddish indentation

Posted by Waaayoff on 22 November 2013 - 01:26 AM

*gosh*. I really feel embarrassed now about my ignorance of the complexity, so thanks for that link.
 
Still would be glad to hear some answers to my question: Nobody had any troubles learning programming because of clashing reading directions ?


My first language is Arabic which is written from right to left. I didn't have any problems because I also know English, which I'm pretty sure is the case for all programmers...

And this indentation makes my eyes bleed :)


#5104614 Globals usage in tutorials and elsewhere.

Posted by Waaayoff on 26 October 2013 - 12:14 PM

I tend to use both Globals and Local Variables.  I use Globals for mundane task which may be used in several Functions through out the coding.

For Example :  int x,y;  // Loop Counters  These I declare up front instead of declaring them in Each function I would use a Counter.

 

 

Oh the humanity




#5103839 The death of D3D9

Posted by Waaayoff on 23 October 2013 - 01:07 PM

Because Windows XP still runs on 39% of PCs.

 

Edit: Also i think some find it easier not to have to deal with shaders at first. They do tend to complicate things a bit.




#5102576 Directx11 animations

Posted by Waaayoff on 19 October 2013 - 01:45 AM

I wrote a simple explanation with code here a while back. Take a look at it and feel free to PM me with any questions.




#5097911 Gerstner wave function [HLSL]

Posted by Waaayoff on 30 September 2013 - 01:31 PM

Thanks for the help!

The code helped a lot, although it doesnt work with a plane for some reason. Still I get the idea and can now write the rest myself.

I appreciate the help! biggrin.png

 

The code works by transforming vertices. A plane only has 4. You need to use a grid.

 

Anytime.




#5097753 Gerstner wave function [HLSL]

Posted by Waaayoff on 30 September 2013 - 01:01 AM

Here's some code I wrote a while back. It's only a test code for a single wave. You will want to create a number of waves at different frequencies to obtain a more realistic look.

cbuffer World
{
	float3 SunDirection;
}

cbuffer Instance
{
	float4x4 WorldViewProj;
}

cbuffer PerFrame
{
	float DeltaT;
}

Texture2D DiffuseTexture;
SamplerState Sampler;

struct VS_IN
{
	float4 position : POSITION;
	float2 uv 		: TEXCOORD0;
};

struct VS_OUT
{
	float4 position	: SV_POSITION;
	float2 uv		: TEXCOORD0;
};

VS_OUT VShader(VS_IN input)
{
	VS_OUT output = (VS_OUT)0;
	
	// Gerstner Wave
	
	float A = 5;	// amplitude
	float L = 50;	// wavelength
	float w = 2*3.1416/L;
	float Q = 0.5;
	
	float3 P0 = input.position.xyz;
	float2 D = float2(0, 1);
	float dotD = dot(P0.xz, D);
	float C = cos(w*dotD + DeltaT/100);
	float S = sin(w*dotD + DeltaT/100);
	
	float3 P = float3(P0.x + Q*A*C*D.x, A * S, P0.z + Q*A*C*D.y);
	
	output.position = mul(WorldViewProj, float4(P,1));
	output.uv = input.uv;

	return output;
}

float4 PShader(VS_OUT input) : SV_Target
{
	return float4(DiffuseTexture.Sample(Sampler, input.uv).rgb, 1);
}

And some literature:

 

http://http.developer.nvidia.com/GPUGems/gpugems_ch01.html

http://hyperphysics.phy-astr.gsu.edu/hbase/waves/watwav2.html

http://www.gamedev.net/blog/715/entry-2249487-ocean-rendering/

http://graphics.ucsd.edu/courses/rendering/2005/jdewall/tessendorf.pdf




#5089195 Managers, which pattern should I use

Posted by Waaayoff on 26 August 2013 - 09:34 AM

...

 

Globals::getInstance()->textureManager()->getTexture("baby.png");

Globals::getInstance()->inputManagers[PlayerId]->isButtonDown('A');

 

Not the best practice, but accessing things easily from everywhere is nice too. Also I cant keep all my other managers singleton-free.

 

That is just ugly. It reminds of me of the OGRE engine and how much i hated its managers. Like said before, there is nothing wrong with passing pointers or localizing functionality.  




#5088370 Is SSAO view dependent?

Posted by Waaayoff on 23 August 2013 - 07:27 AM

Ok so i took another look at the code that uses position directly instead of reconstruction and found a bug. Fixed it and got the following result:

 

vwuy.png

 

Which looks correct, right? If so, it's the damn reconstruction code again. It just won't work!!




#5078741 Per-Pixel Point Light

Posted by Waaayoff on 18 July 2013 - 11:52 AM

Output the normals from the pixel shader as colour. Do they look correct?






PARTNERS