A way to refer to the spawning model?

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

A way to refer to the spawning model?

Post by Imerion »

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. ;)
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Re: A way to refer to the spawning model?

Post by Kjell »

Hi Imerion,
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.
Neither of those properties keep the spawned clone at the position of its parent no.

- 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.
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?
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.

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 370 times
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Post by Imerion »

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.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Imerion,
Imerion 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.
Yea, you don't want to use a separate model for that. Take a look at the attached example :wink:

K
Attachments
Halo.zgeproj
(1.89 KiB) Downloaded 360 times
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Post by Imerion »

Looks much better!

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);
It's this piece I'm not sure about :
m[x,y] = x != y ? 0.0 : 1.0;
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Imerion,
Imerion wrote:Looks much better!
And in case you need to use it in multiple Models, simply wrap it in a function ( ZLibrary ) and call that instead.
Imerion wrote:I haven't worked much with matrixes though. Could you explain how this works?
The 2D loop is a short / lazy version of the following.

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;
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
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Post by Imerion »

Now I get it. Thanks! Will implement this in my game instead of extra models. :)
Post Reply