7 Replies - 895 Views - Last Post: 24 January 2013 - 01:33 PM Rate Topic: -----

#1 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

hlsl - how do i reflect meshes of the same type to be opposite.

Posted 22 January 2013 - 10:08 AM

Hi all and thanks for reading.

My issue is that I wish to know the correct method for reflecting a mesh against another of the same type using the shader.

Im sure this can be done, but I am a noob so that might explain why i cant find any resources that directly point out how to rotate a mesh in hlsl (though i am sure there is etc)

To give you the scenario..
Imagine I have a wing already loaded and flapping by vertex animation in the shader.
I have another copy of that mesh in the program and imitating the movement of the first wing mesh, as it is literally a copy of the first meshes hlsl code that animates the wing, jyst with the function specified for the second mesh etc.

I want the second mesh to appear opposite to the 1st mesh so i have a rudimentary pair of flapping wings, linear in the fashion regarding the flap element.

ATM, I have a mesh with two wings attahced, both on the same side, both flapping in unison. I am desperate to swap one wing to the opposite side of my mesh utilising those wings.

DirectX 10 is seperating me from the men!


I am pretty confident I goota do something around here


	renderMesh(pd3dDevice, g_p_TechniqueWingLeft, &g_wing1);

	//code here to render opposite side i think
       // I think it needs a rotation and a possible D3DXToRadians thingy 

	//currently the pointy wing to differentiate (note: reset this back in shader later)
	renderMesh(pd3dDevice, g_p_TechniqueWingRight, &g_wing2);





Below is the code section manipulating the mesh , this is in my mind the ideal place to do the rotation so it is done here rather than relying on D3DMatrixRotationY or something like that.



VS_OUTPUT RenderTigerWingRightVS(VS_INPUT input)
{
	VS_OUTPUT Output;
	
	//**********************************************************************//
	// Deform the mesh here for the right wing.	                        //
	// .									//
	//**********************************************************************//
	
	float wingBase2 = 0.55;				//The tiger is created with its wing pointing
										//straight out on the x axis, so the wing 
	//wingBase2 = (4/3.14159) / 180;

	if (input.vPos.x > wingBase2 )		//begins at x= tailBase
	{
		float distanceFromBum = wingBase2 - input.vPos.y;
		
		input.vPos.z = g_fTailAngle * distanceFromBum;  //Wag from side to side.
	}

	
	float3 vNormalWorldSpace;
	
	// Transform the position from object space to homogeneous projection space
	Output.Position = mul(input.vPos, g_mWorldViewProjection);
	
	// Whatever we do to the object we must do to its normal vector.    
	vNormalWorldSpace = normalize(mul(input.vNormal, (float3x3)g_mWorld)); // normal (world space)

	// Calc diffuse color    
	Output.Diffuse.rgb = g_MaterialDiffuseColor * g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir)) + 
						 g_MaterialAmbientColor;   
		
	Output.Diffuse.a = 1.0f; 
	
	// Just copy the texture coordinate through
	Output.TextureUV = input.vTexCoord0; 
	
	return Output;    
}

/*********************************END RIGHT WING******************************/






For anyone still reading.......
Help.......
& thanks.
Gruffy

This post has been edited by gruffy: 22 January 2013 - 11:37 AM


Is This A Good Question/Topic? 0
  • +

Replies To: hlsl - how do i reflect meshes of the same type to be opposite.

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: hlsl - how do i reflect meshes of the same type to be opposite.

Posted 22 January 2013 - 07:52 PM

The common solution would be to render half your model and all of its attributes in model view, then multiply the vertices by -1 to render the mirror image.

Something like that you're after?
Was This Post Helpful? 1
  • +
  • -

#3 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: hlsl - how do i reflect meshes of the same type to be opposite.

Posted 23 January 2013 - 02:54 AM

Hey ButchDean, thanks for such a quick reply , as is becoming the usual with your good self and my questions of noob stupidity.
That sounds like an idea but,I already have two meshes in there but both flapping(as are basically two of the same objects) and positioned on the same side.

I was thinking that I may need to translate the Y position by 180 degrees/radians, but am unsure ,if even correct method, how to implement this successfully.

I was trying to imlement this.....
D3DXMatrixTranslate(object1, object2, D3DXToRadian(180));

prior to the render call for the second wing.
However, to no avail......

Thanks again ButchDean for reading and replying

Gruffy
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: hlsl - how do i reflect meshes of the same type to be opposite.

Posted 23 January 2013 - 09:57 AM

No problem, Gruffy.

Pretty much what I said before will work, give it a go to avoid duplication of the object and over complicated math.
Was This Post Helpful? 1
  • +
  • -

#5 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: hlsl - how do i reflect meshes of the same type to be opposite.

Posted 23 January 2013 - 12:09 PM

View PostButchDean, on 23 January 2013 - 09:57 AM, said:

No problem, Gruffy.

Pretty much what I said before will work, give it a go to avoid duplication of the object and over complicated math.



Hey ButchDean, thanks bud for quick reply again.
ng
I know this may be asking alot, but could you by any chance throw some psuedocode at me or possibly help me out by pointing to where i have to implement your suggestion.

I am keen on what you said but am still green behind the ears enough to on keep getting myself muddled up with it.

effectively am i?......
declaring and implementing them odel in my cpp program then also making a copy/instance of it there(how, as at mo i am loading two seperate sdkmeshes of the same wing?).
(i am using the simple sample , so you can imagine its a messy scribble)

Then...

animating the wing in the shader (got this done and working fine so far)

So , you see, my problem is mainly being unsure how to implement those wise words from you, ButchDean, above.

Please dont think I havent searched for this on the Google, I have. My only outcome was that I was either asking the wrong sort of question related to topic or there is little by way of explanation or tutorial for stupid people (RE: me)

A Wish:(hoping the above statement might return some links to google pages that are abundant with the riches I could not find, that we often see on here when someone states they "cant find it on Google")

Thanks again ButchDean, and anyone else who reads this
Gruffy - forever wanting the secret knowledge
Was This Post Helpful? 0
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: hlsl - how do i reflect meshes of the same type to be opposite.

Posted 23 January 2013 - 08:28 PM

In this code:

renderMesh(pd3dDevice, g_p_TechniqueWingLeft, &g_wing1);

//code here to render opposite side i think
      // I think it needs a rotation and a possible D3DXToRadians thingy 

//currently the pointy wing to differentiate (note: reset this back in shader later)
renderMesh(pd3dDevice, g_p_TechniqueWingRight, &g_wing2);



you have g_p_TechniqueWingRight, &g_wing2 in your second call to renderMesh(). My point is you don't need them. What you need to do is between the two calls have some kind of math that mirror-images the behavior of g_p_TechniqueWingLeft, &g_wing1 rather than use the new objects. How you exactly accomplish this I wouldn't know off hand because I need to be familiar with the composition of the objects and the valid operations you can perform on them.
Was This Post Helpful? 1
  • +
  • -

#7 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: hlsl - how do i reflect meshes of the same type to be opposite.

Posted 24 January 2013 - 10:45 AM

AMazeballs ButchDean!

I shall try to get that implemented then , and it does make complete sense over my current approach.

Cheers bud.
U You really are a massive help on here and I hope others appreciate you as much I do.
If not, I have a small room in my house that you could occupy full time and feed me with programming knowledge as and when required.

I only hope I reach a level where I can make that kind of difference to others too, one day.
Gruffy
Was This Post Helpful? 1
  • +
  • -

#8 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: hlsl - how do i reflect meshes of the same type to be opposite.

Posted 24 January 2013 - 01:33 PM

Thanks man. Good luck.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1