Generic Transform Class

Generic Transform Class

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
9heart
Posts: 55
Joined: 16 Sep 2010, 16:14

Generic Transform Class

Post by 9heart »

LocalModelPiece Translation/Rotation/Scale are represented by Matrix4x4, used by glMultMatrixf(modelSpaceMat)

Code: Select all

unit_created(){
for each piece in s3d model
  clone piece
  compose transformation from default values
  instantiate
}

unit_update(){
if unit script changes transform (aim from weapon, walk, etc)
  flag dirty
  recursively update model pieces
     compose piece matrix from script Euler Angles
Draw(glMatrix)
}
My proposal is to give each ModelPiece a generic Transform which internally handles all translation/rotation/scale.

Instead of the following members

Code: Select all

	float3 pos; // translation relative to parent LMP, *INITIALLY* equal to original->offset
	float3 rot; // orientation relative to parent LMP, in radians (updated by scripts)
	float3 dir; // direction from vertex[0] to vertex[1] (constant!)

	CMatrix44f pieceSpaceMat; // transform relative to parent LMP (SYNCED), combines <pos> and <rot>
	CMatrix44f modelSpaceMat; // transform relative to root LMP (SYNCED)
Each LocalModelPiece would instead have a transform object which encapsulates the above members and the operations performed on them (ComposeTransform, ComposeRotation...)

this would allow customization of how rotation are handled, be it euler angle concatenation or matrix multiply == give game developers control over speed/memory tradeoffs in calculations

My concern is that certain callouts for handling unit states are entirely dependent on LocalModelPiece position/rotation, so much of the weapon aiming system/collisions system needs to be reworked as well.

===========
im going to dump some ideas here

AFAIK the two methods for calculating important weapon-related positions are

[code]
relWeaponPos = owner->script->GetPiecePos(owner->script->AimFromWeapon(weaponNum));
weaponPos = owner->GetObjectSpacePos(relWeaponPos);
[/code]

..which respectively return...

[code]
return (modelSpaceMat.GetPos() * WORLD_TO_OBJECT_SPACE); // combined translation/rotation/scale matrix4x4

and

return ((pos + (frontdir * p.z) + (rightdir * p.x) + (updir * p.y)); //float3 pos very bottom of Object

[/code]


Last edited by 9heart on 17 Dec 2014, 02:37, edited 1 time in total.
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: Generic Transform Class

Post by REVENGE »

Gayter are no longer popular.
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Generic Transform Class

Post by Anarchid »

If the endgoal is to make life of people attempting anything fancy like IK or blending easier...

Maybe just bite the bullet and make spring's backend work on quats? :P
9heart
Posts: 55
Joined: 16 Sep 2010, 16:14

Re: Generic Transform Class

Post by 9heart »

Anarchid wrote:make spring's backend work on quats? :P
The reason float3 is used for all translation/rotation is floating point gives predictable results on all processors (AMD vs Intel, x86 vs x64, etc) and operating systems.

Numerical stability comes into play when concatenating (many) rotations, e.g. in rotational animations or deep scene graphs. Rotation matrices tend in general to degenerate earlier than quaternions do (Quaternions are 4 floats vs Matrix 16).

Euler Angles (3 Floats) probably does not degenerate much at all (helpful for deterministic/synchronous RTS's)


Only way to know for sure: parameterize your ModelPiece class by orientation representation (i.e. matrix or quaternion), and then use metaprogramming techniques (templates?) to perform (or not perform) the necessary operations and conversions depending on the type of representation.

Then you can compare one version of the program with quaternions as the base orientation representation with another that uses matrices (or whatever).
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Generic Transform Class

Post by Anarchid »

Spring uses streflop anyway for floats, so there's zero deterioration.

(Also this is why we cant have android)
Post Reply

Return to “Engine”