• 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
george7378

When to calculate the bounding sphere

6 posts in this topic

Hi everyone,

 

If I'm calculating the bounding sphere of my mesh (using D3DXComputeBoundingSphere), should I do it before or after I have transformed the mesh using the world matrix? I'm guessing after, but I just want to check!

 

Thanks!

0

Share this post


Link to post
Share on other sites

You can do it any time you wish, including once-only at load time.  The great thing about a bounding sphere is that you only need to transform it's midpoint to get it to a different space.

1

Share this post


Link to post
Share on other sites

Hi George,

 

This is a bit tricky, when you do it is not important, it's important that you transform/ rotate etc. at the right time.

I found out by playing around quite I while. Here's what I do now, in pseudo code:

 

- lock the vertexbuffer of the mesh

- applying scaling and rotations on the vertices, for this mesh instance

- compute boundingsphere for complete meshinstance (0,0,0 being in local space, mesh center)

- do the same for each submesh (attr of the d3dxmesh)

- translate the worldpostion for both the full mesh instance as all submeshes 

 

Keep in mind future plans, if you're gonna use mesh instances, then you should not limit yourself by calculation it on mesh base, but do it on mesh instance base. For example I do this within my mesh instance class (using a specific mesh). Which also has the rotation, translation, etc. matrices for the mesh instance.

 

It's important to calculate it in local space and keep track of scaling, to prevent weird results.

I also calculate it for the submeshes (attributes of the d3dxmesh).

0

Share this post


Link to post
Share on other sites
Create any bounding boxes/spheres for a given mesh once at load-time (or embed them into your custom file format) and apply the same transformations on them as those that are applied to your mesh.
 
For spheres, that means:
	/**
	 * Creates a new sphere that represents the given sphere modified by the given matrix.
	 *
	 * \param _sSphere The sphere to modify.
	 * \param _mMat The matrix by which to modify the given sphere.
	 * \return Returns a sphere that has been scaled and moved by the given matrix.
	 */
	CSphere LSE_FCALL CSphere::CreateSphereFromSphereAndMatrix( const CSphere &_sSphere, const CMatrix4x4 &_mMat ) {
		CSphere sRet;
		CVector3 vRow;
		_mMat.GetRow( 0UL, vRow );
		sRet.r = vRow.LenSq();
		_mMat.GetRow( 1UL, vRow );
		sRet.r = CStd::Max( sRet.r, vRow.LenSq() );
		_mMat.GetRow( 2UL, vRow );
		sRet.r = CStd::Max( sRet.r, vRow.LenSq() );
		sRet.r = CMathLib::Sqrt( sRet.r ) * _sSphere.r;
		sRet.c = _mMat * _sSphere.c;
		return sRet;
	}
The midpoint of the sphere is simply fed into the matrix and returned as a new point in space.
The radius of the sphere is modified by the largest scaling factor in the matrix. This can be omitted for matrices with no scaling factor.


L. Spiro Edited by L. Spiro
0

Share this post


Link to post
Share on other sites

The great thing about a bounding sphere is that you only need to transform it's midpoint to get it to a different space.

Be careful there, things get really hairy when dealing with non-uniform scaling.

 

I'd generally suggest that you avoid non-uniform scaling everywhere, for simplicity, but if you can't, bounding boxes start to look a whole lot better.

0

Share this post


Link to post
Share on other sites

The great thing about a bounding sphere is that you only need to transform it's midpoint to get it to a different space.

Be careful there, things get really hairy when dealing with non-uniform scaling.

 

I'd generally suggest that you avoid non-uniform scaling everywhere, for simplicity, but if you can't, bounding boxes start to look a whole lot better.

 

This is true.

 

Since the OP talked about transforming the mesh using the world matrix, and since you generally don't see scaling in a world matrix, it can probably be discounted as a specific problem for this question, but it is still correct to highlight it.

1

Share this post


Link to post
Share on other sites
The code I posted handles this problem.  To transform a bounding sphere to handle any scaling, uniform or not, simply look for the longest row vector (this is Direct3D after all) in the upper-left 3×3 area and multiply the radius by the length of that vector.

since you generally don't see scaling in a world matrix

I am not sure what you mean by this. Scale, rotation, and position are all part of the world matrix.
 
 
L. Spiro Edited by L. Spiro
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