• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Hawkblood

Matrix math help

17 posts in this topic

I can't believe I haven't needed this before..... How would you lerp between 2 matrix's???

 

Is there a function already out there or would I need to make my own? If I make my own, how?

0

Share this post


Link to post
Share on other sites

You can't guarantee (i.e. it usually won't be true) that the matrix will be orthonormal (each row/column perpendicular and normalised), orthogonal (each row/column perpendicular) or each row or column linearly independent though. You normally have to re-orthonormalise your matrix after a lerp (e.g. via Gram-Schmidt) but then you may as well use quaternion/scale/translation components then.

Edited by Paradigm Shifter
1

Share this post


Link to post
Share on other sites

Well, ApochPiQ answer is probably what you needed to hear, but in fact lerping between 2 matrices is a perfectly well-defined operation. Matrices can be added, subtracted and scaled (i.e., multiplied by constants). Verify a couple of axioms more, and it turns out they are a vector space. You can always compute t*v + (1-t)*w, and that's what lerp is. Notice that the non-commutative nature of matrix multiplication doesn't enter the picture, because we are only multiplying the matrices by scalars, and that works just fine.


Yes, lerping matrices is defined, but it will violate the semantics of the matrix in the general case, as Paradigm Shifter elaborated on.
1

Share this post


Link to post
Share on other sites

It'd be interesting to know what your intentions are.

Animation. I created a function to load a mesh (.x) with animation matrices. I need a way to move/rotate the object smoothly. Given that each frame has its own matrix, if I want it to animate very slowly would pose a problem. The difference between, say, frame0 and frame1 could be a rotation of 22.5 degrees, but I want it to move at 0.001 degree increments. Without a way to lerp, I could only show frame0 or frame1. With lerping, I could show incremental rotation of 0.001 each frame (smooth)......

 


orthonormal

Wow. I think I understand what that means (wiki). I am still not sure I need to worry about it (considering how I want to lerp). I'm pretty sure I can lerp the location part of the matrix, but the rotation I may have a problem with. As I understand, the "rotation" parts of the matrix is -1 to +1. Could I simply make a quaternions (after removing the "location"), lerp between the quaternions and then assemble the final matrix?

0

Share this post


Link to post
Share on other sites

Yes, use quaternions for that.

 

EDIT: Kind of. This bit doesn't make sense: As I understand, the "rotation" parts of the matrix is -1 to +1

 

The rotation part (assuming no scale/shear/other shenanigans) is the upper 3x3 matrix of a 4x4, if it is orthonormal you can extract the rotation as a quaternion and slerp.

Edited by Paradigm Shifter
1

Share this post


Link to post
Share on other sites

Kind of. Non-uniform scaling (i.e. scale x, y, z by different amounts) can be a pain.

I saw, somewhere, the breakdown of DX matrix. I don't remember every part.

 

m(3,0),m(3,1),m(3,2) is the location.

m(3,3) is uniform scaling.

 

I don't remember how to pull out the rest....

 

 

EDIT:

Gotta ask the right question in Google.

 

http://msdn.microsoft.com/en-us/library/windows/desktop/bb206269(v=vs.85).aspx

 

This breaks it down..... I just need to figure out how to extract the xyz scaling from (0,0),(1,1),and (2,2)...........

Edited by Hawkblood
0

Share this post


Link to post
Share on other sites

You should use quaternions for interpolation, as others have mentioned. Then you have a couple of options about how exactly to do the interpolation: slerp and nlerp. If consecutive key frames are not too different, you can get away with nlerp, which is way simpler.

 

Quaternion nlerp(Quaternion q1, Quaternion q2, float lambda) {
  if (dot_product(q1,q2) < 0)
    q2 = -q2;
  Quaternion lerp = lambda * q1 + (1.0f - lambda) * q2;
  return lerp * (1.0f / abs(lerp));
}
0

Share this post


Link to post
Share on other sites

Premature optimisation is the root of all evil though ;) Should try and get it working with slerps first.

 

Extracting scale isn't as straightforward as reading (0,0) (1,1) and (2,2) though, it's the length of the row/column vectors in the rows/columns I think? (Not thinking too well I have just come back from Belgium after travelling all day).

0

Share this post


Link to post
Share on other sites

When using homogeneous coordinates, the matrix of a projective transformation is only determined up to scaling. Typically one picks m(3,3)=1, but I guess you could also effectively scale everything else in the matrix by setting m(3,3)=1/scale. You would have to be careful to divide the translation vector by `scale' as well. I haven't seen anyone doing this, but it would probably work.

1

Share this post


Link to post
Share on other sites

Think I got something:

D3DXMATRIX MatrixLerp(D3DXMATRIX &M1,D3DXMATRIX &M2,float s){
	D3DXMATRIX m1,m2;//**** this is so that the original matrices are unafected....
	m1=M1;
	m2=M2;
	//strip out the locations lerp them
		//************ NOTE: SCALING IS NOT FACTORED INTO THE LOCATION OF THE MATRICES. 
	D3DXVECTOR3 locFinal,loc1,loc2;
	loc1=D3DXVECTOR3(m1(3,0),m1(3,1),m1(3,2));
	loc2=D3DXVECTOR3(m2(3,0),m2(3,1),m2(3,2));
	D3DXVec3Lerp(&locFinal,&loc1,&loc2,s);
	//remove the location from the matrices
	m1(3,0)=m1(3,1)=m1(3,2)=
	m2(3,0)=m2(3,1)=m2(3,2)=0;

	//do the scale (only uniform scaling is accepted because I can't figure out how to do non-uniform
	float scale=m1(3,3)*(1.0f-s)+m2(3,3)*s;
	D3DXMATRIX tmp;
	float is=1.0f/m1(3,3);
	D3DXMatrixScaling(&tmp,is,is,is);
	m1*=tmp;
	is=1.0f/m2(3,3);
	D3DXMatrixScaling(&tmp,is,is,is);
	m2*=tmp;

	D3DXQUATERNION qf,q1,q2;
	D3DXQuaternionRotationMatrix(&q1,&m1);
	D3DXQuaternionRotationMatrix(&q2,&m2);

	D3DXQuaternionSlerp(&qf,&q1,&q2,s);

	D3DXMATRIX out;
	D3DXMatrixRotationQuaternion(&out,&qf);
	D3DXMatrixScaling(&tmp,scale,scale,scale);
	out*=tmp;
	out(3,0)=locFinal.x;
	out(3,1)=locFinal.y;
	out(3,2)=locFinal.z;

	return out;
}

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0