I currently found myself in a situation where I have created a bunch of model clones, and then need each of these clones to have another model drawn at the same position at all times. These last models are spawned from within the main models, and use both UseSpawnerPosition and SpawnerIsParent.
What I need to do though, is to update the position of these sub-models so it always stays the same as the spawning models. If there was only once of each, I could do :
CurrentModel.Position.X = OriginalModel1.Position.X;
But since I have many of these clones spawned, there is no specific way to refer to them.
Or is there? I'd be really happy if I could use something like Parent.Position.X.
The last programming language I used did it that way, so I'm sort of used to it.
A way to refer to the spawning model?
Moderator: Moderators
Re: A way to refer to the spawning model?
Hi Imerion,
- The UseSpawnerPosition property only causes the SpawnModel.Position property to be relative to the position of the model which spawned it.
- The SpawnerIsParent property only causes the child to be destroyed when the parent is destroyed.
Thing is though, do you really need to do this? Can you explain your exact situation? There might be simpler / better / faster solutions.
K
Neither of those properties keep the spawned clone at the position of its parent no.Imerion wrote:I currently found myself in a situation where I have created a bunch of model clones, and then need each of these clones to have another model drawn at the same position at all times. These last models are spawned from within the main models, and use both UseSpawnerPosition and SpawnerIsParent.
- The UseSpawnerPosition property only causes the SpawnModel.Position property to be relative to the position of the model which spawned it.
- The SpawnerIsParent property only causes the child to be destroyed when the parent is destroyed.
Sure there is The easiest solution is to use a Variable ( of the type model ) in the Definitions of your child model that is set to its parent. Attached is a example that uses this approach.Imerion wrote:What I need to do though, is to update the position of these sub-models so it always stays the same as the spawning models. If there was only once of each, I could do :
CurrentModel.Position.X = OriginalModel1.Position.X;
But since I have many of these clones spawned, there is no specific way to refer to them.
Or is there?
Thing is though, do you really need to do this? Can you explain your exact situation? There might be simpler / better / faster solutions.
K
- Attachments
-
- Children.zgeproj
- (2.59 KiB) Downloaded 454 times
That is exactly was I was looking for and works great! Thanks! Cool looking example by the way.
The exact situation is that each object in my game is drawn with a halo around them, to create a nice lighting effect. For most models I can include this in it's Render, but a few objects rotate. And since this halo is a sprite, it would rotate with the object looking flat, ruining the effect. So I thought I'd create a second object for the halo at the same position as the original object.
If I could exclude part of the render stack from rotating with the model, that would be a more elegant solution.
The exact situation is that each object in my game is drawn with a halo around them, to create a nice lighting effect. For most models I can include this in it's Render, but a few objects rotate. And since this halo is a sprite, it would rotate with the object looking flat, ruining the effect. So I thought I'd create a second object for the halo at the same position as the original object.
If I could exclude part of the render stack from rotating with the model, that would be a more elegant solution.
Hi Imerion,
K
Yea, you don't want to use a separate model for that. Take a look at the attached exampleImerion wrote:The exact situation is that each object in my game is drawn with a halo around them, to create a nice lighting effect. For most models I can include this in it's Render, but a few objects rotate. And since this halo is a sprite, it would rotate with the object looking flat, ruining the effect. So I thought I'd create a second object for the halo at the same position as the original object.
If I could exclude part of the render stack from rotating with the model, that would be a more elegant solution.
K
- Attachments
-
- Halo.zgeproj
- (1.89 KiB) Downloaded 442 times
Looks much better!
I haven't worked much with matrixes though. Could you explain how this works?
It's this piece I'm not sure about :
m[x,y] = x != y ? 0.0 : 1.0;
I haven't worked much with matrixes though. Could you explain how this works?
Code: Select all
mat4 m;
getMatrix(0, m);
for(int x=0; x<3; x++)
{
for(int y=0; y<3; y++)
{
m[x,y] = x != y ? 0.0 : 1.0;
}
}
setMatrix(0, m);
m[x,y] = x != y ? 0.0 : 1.0;
Hi Imerion,
Which basically (re)sets the rotation & scale components of the modelViewMatrix to scale = {1,1,1} and no rotation.
Anyway, "m[x,y] = x != y ? 0.0 : 1.0;" part compares the x and y values. When they are the same the value should be 1, when they are different it should be 0.
K
And in case you need to use it in multiple Models, simply wrap it in a function ( ZLibrary ) and call that instead.Imerion wrote:Looks much better!
The 2D loop is a short / lazy version of the following.Imerion wrote:I haven't worked much with matrixes though. Could you explain how this works?
Code: Select all
m[0,0] = 1; m[1,0] = 0; m[2,0] = 0;
m[0,1] = 0; m[1,1] = 1; m[2,1] = 0;
m[0,2] = 0; m[1,2] = 0; m[2,2] = 1;
Anyway, "m[x,y] = x != y ? 0.0 : 1.0;" part compares the x and y values. When they are the same the value should be 1, when they are different it should be 0.
K