Scale an Entity
-
- Posts: 172
- Joined: Sat Sep 24, 2011 7:31 am
Scale an Entity
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
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.
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.
-
- Posts: 172
- Joined: Sat Sep 24, 2011 7:31 am
Re: Scale an Entity
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!
-
- Posts: 172
- Joined: Sat Sep 24, 2011 7:31 am
Re: Scale an Entity
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
Here's a few options:
-Increase the CollisionMargin of the triangle (spherical expansion)
-WrappedShape of cylinders (or whatever else)
-Use a ConvexHullShape
-Increase the CollisionMargin of the triangle (spherical expansion)
-WrappedShape of cylinders (or whatever else)
-Use a ConvexHullShape
-
- Posts: 172
- Joined: Sat Sep 24, 2011 7:31 am
Re: Scale an Entity
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?Norbo wrote:Increase the CollisionMargin of the triangle
Re: Scale an Entity
Correct, it is a spherical expansion.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?
-
- Posts: 172
- Joined: Sat Sep 24, 2011 7:31 am
Re: Scale an Entity
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?Norbo wrote:Correct, it is a spherical expansion.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
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.
-
- Posts: 172
- Joined: Sat Sep 24, 2011 7:31 am
Re: Scale an Entity
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
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).
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).
-
- Posts: 172
- Joined: Sat Sep 24, 2011 7:31 am
Re: Scale an Entity
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
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.What if I don't want the points to be centered about the origin?
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.
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.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.
-
- Posts: 172
- Joined: Sat Sep 24, 2011 7:31 am
Re: Scale an 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: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.What if I don't want the points to be centered about the origin?
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.
So make something like a position function based on scale instead of velocity? So, something like this?Norbo wrote: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.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.
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
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.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?
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.
Yup.So make something like a position function based on scale instead of velocity? So, something like this?