Page 1 of 2
Scale an Entity
Posted: Sat Mar 03, 2012 1:11 am
by snoozbuster
Hey, I'm assuming there's some fairly simple way to scale an Entity, but I don't see it offhand. Could you enlighten me? If it doesn't exist, I'll probably just add ScaleVelocity or something like that to the Entity class, but... Don't know how hard that would be. Thanks!
Re: Scale an Entity
Posted: Sat Mar 03, 2012 1:17 am
by Norbo
Individual shapes have individual scaling mechanisms (radius for sphere, width/height/length for box, etc.). There is no automatic universal scaling mechanism built into the entity, but you can wrap any convex entity shape in a TransformableShape and apply arbitrary linear transforms including scaling.
Wrapping a shape in a TransformableShape has a tiny overhead and also prevents any special cases from being used. Transformable-wrapped box-box/sphere-sphere/box-sphere (and so on) cases just become general convex-convex cases.
In general, I recommend sticking to the most direct shape possible without wrapping it, but the option is there.
Re: Scale an Entity
Posted: Sat Mar 03, 2012 1:26 am
by snoozbuster
Alright. I can use Triangle for my purposes, I just have to figure out how I want to do it; right now there's no differentation between convex shapes and Entities. Thanks for the info!
Re: Scale an Entity
Posted: Sat Mar 03, 2012 2:45 am
by snoozbuster
Ermm, I was working, and I noticed that TriangleShapes don't appear to have depth, but yet they have a function that computes volume. The triangle I'm in need of needs to have depth... Is there a shape that provides that?
Re: Scale an Entity
Posted: Sat Mar 03, 2012 2:49 am
by Norbo
Here's a few options:
-Increase the CollisionMargin of the triangle (spherical expansion)
-WrappedShape of cylinders (or whatever else)
-Use a ConvexHullShape
Re: Scale an Entity
Posted: Sat Mar 03, 2012 3:02 am
by snoozbuster
Norbo wrote:Increase the CollisionMargin of the triangle
This seems simplest, but what would I want to do to accomplish that? If I increase it, won't it increase the margin on all the vertices, not just on the Z depth?
Re: Scale an Entity
Posted: Sat Mar 03, 2012 3:04 am
by Norbo
This seems simplest, but what would I want to do to accomplish that? If I increase it, won't it increase the margin on all the vertices, not just on the Z depth?
Correct, it is a spherical expansion.
Re: Scale an Entity
Posted: Sat Mar 03, 2012 3:11 am
by snoozbuster
Norbo wrote:This seems simplest, but what would I want to do to accomplish that? If I increase it, won't it increase the margin on all the vertices, not just on the Z depth?
Correct, it is a spherical expansion.
In that case, ConvexHullShape looks like the only way I'm gonna be able to do it. Out of curiousity, though, if I ask ConvexHullShape to give me the most exteme vertex, and there are multiple points that satistify extremity in the given direction, does it just return the first one?
Re: Scale an Entity
Posted: Sat Mar 03, 2012 3:16 am
by Norbo
If I remember right, yes. But if two points are truly that close to being equal along the direction, there's likely to be tiny numerical differences which would override the order.
Re: Scale an Entity
Posted: Sat Mar 03, 2012 3:48 am
by snoozbuster
Hmm... Alright, how would you recommend scaling a triangle of six points on each of the axes? I was previously using GetLocalExtremePointWithoutMargin with the unit vectors, but that doesn't seem like it'll work now that I have two points that need to satisfy that condition. For example, if I have a triangle with points at (0, 0, 0), (1, 1, 1), (-1, -1, -1) and Z depth of some depth h and I want to reduce it to (0, 0, 0), (0.5, 0.5, 1), (-0.5, -0.5, -1) and Z depth of h, which is half the X and Y dimensions, how would I do that?
Re: Scale an Entity
Posted: Sat Mar 03, 2012 6:13 am
by Norbo
Multiply each component of each point by the scaling factor for that axis.
For points which are already centered, such as those in a convex hull shape, that's it. If it's not centered, then simply multiplying will put the shape further from or closer to the origin, but that doesn't matter if the points are going to be put into a convex hull shape (which recenters it anyway).
Re: Scale an Entity
Posted: Sat Mar 10, 2012 8:26 am
by snoozbuster
Sorry it's taken so long to reply, I was working on other things and didn't want to reply until I'd tried it, but I do have one question after looking at your reply again... What if I don't want the points to be centered about the origin? If I give it points all in the general area of (20, 20, 20), plus or minus a few to make a triangle with depth, are they all gonna stay over there or be centered at the origin? Also, if I wanted to decrease the scale gradually each frame, how would that work with multiplying by a scale factor? It's not like you can multiply by 0.99 70 times to get a scale of 0.3... Those darn decimals.
Re: Scale an Entity
Posted: Sat Mar 10, 2012 9:05 am
by Norbo
What if I don't want the points to be centered about the origin?
When a convex hull is created, it recenters the points around the local origin. The position is used as the Entity's Position, so that the points end up in the same place.
When scaling an already-created object's vertices, you can just rescale the shape. The Position won't change automatically when doing this; rescaling the shape will not move the entity.
Also, if I wanted to decrease the scale gradually each frame, how would that work with multiplying by a scale factor? It's not like you can multiply by 0.99 70 times to get a scale of 0.3... Those darn decimals.
There's a beginning state and an ending state that needs to be reached within a specified time period. At any time in between, the function defining the scaling can be sampled to determine the scale. You don't have to iteratively rescale based on the previous scaled vertices; work off of an unscaled base set of vertices.
Re: Scale an Entity
Posted: Sun Mar 11, 2012 12:32 am
by snoozbuster
Norbo wrote:What if I don't want the points to be centered about the origin?
When a convex hull is created, it recenters the points around the local origin. The position is used as the Entity's Position, so that the points end up in the same place.
When scaling an already-created object's vertices, you can just rescale the shape. The Position won't change automatically when doing this; rescaling the shape will not move the entity.
Alright, so is there a way to get the center moved to someplace else? If I wanted to have the center around one of the points, could I easily accomplish that or would I have to factor in a slight bit of LinearVelocity to compensate for it?
Norbo wrote:
Also, if I wanted to decrease the scale gradually each frame, how would that work with multiplying by a scale factor? It's not like you can multiply by 0.99 70 times to get a scale of 0.3... Those darn decimals.
There's a beginning state and an ending state that needs to be reached within a specified time period. At any time in between, the function defining the scaling can be sampled to determine the scale. You don't have to iteratively rescale based on the previous scaled vertices; work off of an unscaled base set of vertices.
So make something like a position function based on scale instead of velocity? So, something like this?
Code: Select all
private List<Vector3> vertsAtT(List<Vector3> unscaled, Vector3 targetScale, float endingTime, float currentTime)
{
// multiply targetScale by currentTime minus endingTime
// scale the unscaled list by the new scale
// return scaled list
}
Re: Scale an Entity
Posted: Sun Mar 11, 2012 12:45 am
by Norbo
Alright, so is there a way to get the center moved to someplace else? If I wanted to have the center around one of the points, could I easily accomplish that or would I have to factor in a slight bit of LinearVelocity to compensate for it?
You can accomplish any combination of scaling and moving by scaling the vertices in local space and setting the Position of the entity in world space. Using a velocity to change the position of the entity over time instead would be fine too. Teleporting objects is indeed usually frowned upon. However, rescaling a shape is already performing a nonvelocity motion; collision response with dynamically scaling shapes will be 'squishy' at best and friction will ignore the scaling. Gradually teleporting the object will only worsen the issue a little.
Some persistent manifold based systems may also cache contacts with the expectation that the shape isn't changing; you may need to call ClearContacts on every pair associated with the scaling entity when changing the scale if invalid contacts are persisting.
So make something like a position function based on scale instead of velocity? So, something like this?
Yup.