Transformation lags/overtakes vector when trying to deform along path via HLSL

Recommended Posts

I'm trying to implement animation by deformation along a path in Miku Miku Dance.  This problem is interesting to me, it opens up new options to animators, and it seems like a good way for me to learn more about transformations.  I'm doing my deformation in a HLSL vertex shader, using bones as path nodes, using quaternions to create matrices to rotate my vertices, traveling down the path and rotating as I go.  I don't understand quaternion math, but I found this code online, and it's worked for me other places

It's almost right.  I really think I'm doing the right thing.  Almost.  But my angles aren't right.  Demonstrated in the picture (yes, I'm using an actual arrow model to test).

At 90 degree intervals, the angles are correct.  As I go from no transformation to 90 degrees, the transformation lags the vector.  From 90 degrees to 180 degrees, the transformation overtakes the vector.  This is symmetrical; transformation lags the -45 degree vector same as +45 degrees.

Here is the code I've written.  I'm trying to include only relevant bits.  I can include everything if anybody wants, just trying to spare you.  This is for shader model 3.0/DX9.

...
float4 pos0 : CONTROLOBJECT < string name = PATHMODEL; string item = "0"; >;
//leave at origin, indicates beginning of deformation
float4 pos1 : CONTROLOBJECT < string name = PATHMODEL; string item = "1"; >;
//first node, proceeding from origin
...
float3 rotateAxis(float3 pos, float3 origin, float3 axis, float angle) {
//rotates pos around origin in axis by angle in rads using quaternion
pos -= origin;
float4 q;
q.xyz = axis*sin(angle/2.0f);
q.w = cos(angle/2.0f);
q = normalize(q);
float3 temp = cross(q.xyz, pos) + q.w * pos;
pos = (cross(temp, -q.xyz)+dot(q.xyz,pos)*q.xyz+q.w*temp);
pos += origin;
return pos;
}
...

VS_OUTPUT Basic_VS...
float4 wPos = mul( Pos, WorldMatrix );
float3 vec0 = YVEC;
//primary axis, as vertices travel in positive Y axis they are deformed
float3 vec1 = normalize(pos1.xyz - pos0.xyz);
float extent = wPos.y; extent -= pos0.y;
if (extent > 0.0f) {
float3 axis = cross(vec0, vec1);
float angle = (PI*(1.0f-((dot(vec0,vec1)) + 1.0f)/2.0f));
wPos.xyz = rotateAxis(wPos.xyz, pos0.xyz, axis, angle);
}
Out.Pos = mul( wPos, ViewProjMatrix );
...

Am I misunderstanding the dot product here?  Does my function not do what I think it does?  Something else?  Any help is greatly appreciated.  I'm an amateur, I try to read and learn, but no formal education, no experience, and no people around me studying the same things, and I'm really grateful for the people on this forum that provide help.

Share on other sites

On a night's rest, it seems to me that I shouldn't be using angle = PI*(1.0f-((dotProd + 1.0f)/2.0f)); but should instead be using angle = acos(dotProd); .  However, this apparently gives me an apparently identical response through angles up to Pi/2 radians, and breaks down when it reaches something like Pi*4/3.  Seems like it's right theoretically, but looks entirely wrong.

The relationship is not a power relationship.  Nevertheless, using the code I provided above, but adding dotProd = 1.0f - pow(1.0f-dotProd, 0.25f); gives me something very close to correct.  Currently I'm just hacking my way through it with this correction, creating a new node at the not-quite-right angle in order to approach the correct path.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628714
• Total Posts
2984353
• Similar Content

• Hello people of gamedev.net

Me and my team have been working on a MMORPG game with Unreal Engine 4 for quite some time now.
We are seeking beta tester's and have beta key's available to people who sign up on our website.
Feel free to register on our forums, We can talk about the game and help everyone get a better idea of what type of game it is.

Legion is a 3D fantasy MMORPG that has features including massive scale battles, unique characters and monsters, customization of avatars, special equipment and more. Players choose between the starter stats of Warrior, Magician, Archer and character advancement occurs through a mix of questing, PvP, Guild Wars, and hunting, depending upon player preference. In Legion, completely open PvP battles take place between members of the two warring factions.

We plan to make this game very competitive and exciting
• By Matuda
Hello!
Trying to create a physics puzzle game in my "free" time.
So far it's going very steady, but slow.
Hope to get some feedback from you!

Area 86 is a physics-based game, that lets you control a robot at a secret place in space.
From simple item moving to custom imagined solutions with item picking, throwing, combining and activating!
Explore & examine all possibilities each place has to offer and do your best to get further.
But remember, each action has consequences and thus could break or make something unexpected.

Quick overlook of main features:
Physics-based gameplay with no bugs or whatsoever Tasks that give you more clue on how to do things wrong Controllable robot who can be blamed for all consequences Includes more than 1 level and each level contains less than 12 possible tasks to complete [ not in free version ] Secret places and hidden objects for extra challenge
One fully completable level with 6 tasks and 2 hidden special items to discover.
From the task list, 2 are main tasks which you should complete to get further and then there are 4 other tasks that should challenge your thinking.
One of the secret items is visible instant, but you need to figure out how to collect it, while the other special item is hiding.
Another extra feature is visual hints, that should force your thinking of discovering features.

• well, i have started developing games last year, alone , I made a singleplayer 3d openworld rpg on unity you can look at it on googleplaystore ( kooru stone rpg ) whatever, this year, i wanted to make mmo, which gone really fine until I first try real hosting, I was working on "wamp" until then. The reason i am desperate now is that the way my game works.
On my pc, using wamp mysql , with localhost as host for my game, i was testing my mmorpg with using andorid emulators, ofcourse no lag no issues no restrictions, beautiful dream... But then, I wanted to get real host from web, so, I rent a basic, cheaphest ever web host ( 10\$ year ), and transferred my php files along with sql database.
So, I launched the game, still no issues, tried to handle 2-3 players by using my pc, phone, friend's phone...
After a while, ( after really short time (3-4mins)) host started not to respond, beacause those web hosting were not fit to handle mmos, i predicted that.
now what i am explaining is that my game works like this and asking what way should i use to handle it :
- Creates web request ( like : webhost.com/game/getplayerdata.php?ID=2 )
-Reads request ( request result be like = "ID2-GoodGuyXx-23-123-4-123-43 )
-Builds player using result string
-does similar requests REEAALY FREQUENTLY  ( total requests of 8 - 12 times per seconds )
With my current ultimate cheap web hosting, i can handle 2 players with low lag ( lol ) but, i want to handle around 20-100 players,
just need a clear path, i have been struggling with google cloud sql and other vps server dedicated server options, i dont wanna pay much and get ripped off.

• Hi,

I have a triangle,oriented in a 3D Plane i.e. I have my vertices as (x1,y1,z1) ; (x2,y2,z2) and (x3,y3,z3)
I am trying to convert this triangular facet to voxelised model i.e.
Along each edge,I am applying Bresenhams 3D Line algorithm and generating intermediate points.After generating intermediate points, I want to fill the inside region.
I have been searching for some algorithm like flood filling,but did not find anything relevant till now.
I would be really glad,if some one can provide an algorithm for achieving this.
I basically have a List of tuple for storing all the (x,y,z) data created along the edges.(generated using Brsenhams 3D Line algorithm).
Now,I want an algorithm,which creates cubes in the inside region.
• By DavidMT
A team has a position open for a 3D artist and/or modeler.
Excellent opportunity to gain experience working with a team remotely. Great chance to extend your portfolio Candidates, if successful have the chance to join the team permanently with entry-level financial benefits. Revenue Share What they expect
Excellent communication skills Portfolio of previous work If you are interested please attach a CV and/or relevant works to jobs@iamdavidmt.com

• 23
• 11
• 10
• 13
• 14