Feb 1, 2011 at 6:21 PM

Perhaps this is an implementation question or maybe it's just some part of C# syntax I've not discovered yet.  I want to change the behavior of Node Manipulation for my object.  I was going to try and override the method, but it turns out it is an event.  So I can add my own Event Handler, but the original handler is still active so I have to turn off InteractionEnabled.  I would remove the default handler but I don't know how to do that from outside the class.

It seems to me that it should either be a method or InteractionEnabled should add or remove the event as needed or some other more flexible approach.  Comments?

Feb 1, 2011 at 7:13 PM

If you set InteractionEnabled to false and add your event handler you should be able to do all the manipulation yourself without the original event handler disturbing anything. 


Feb 1, 2011 at 7:53 PM

Yeah.  That's the approach I took, but it's still calling the Node's event and I was looking for a better solution.

Feb 2, 2011 at 5:50 AM

Isn't it ignoring the functionality in the Nodes event, meaning that you have full control?   

One way could be that the event handler used internall in Node could be virtual and you could override it.  

Feb 2, 2011 at 5:20 PM

No.  ManipulationDelta += Method adds a second event handler.  I'm not sure which one fires first, but they both do fire.  You can test this with the Rubics Cude sample.

I've gone back an forth on this.  I like that there's a default behavior for testing, but ultimately I don't think it should be a feature.  If it is to be a feature, lose the event code and just make it an overrideable method.  If it's to stay as an event, lose the InteractionEnabled property and only define the event handler when needed.  Or alternately, use the InteractionEnabled property to turn the event on and off like so:

private bool _InteractionEnabled = false;
public bool InteractionEnabled
   get { return _InteractionEnabled; }
      _InteractionEnabled = value;
      if (_InteractionEnabled)
         ManipulationDelta += NodeManipulationDelta;
         ManipulationDelta -= NodeManipulationDelta;
Feb 2, 2011 at 6:33 PM

I'm not sure I'm following you. 

The NodeManipulationDelta() method on Node has the following implementation : 

		void NodeManipulationDelta(object sender, ManipulationDeltaEventArgs args)
			if (InteractionEnabled)
				var world = World;
				var rotation = Matrix.CreateRotation((float)-args.DeltaY, (float)-args.DeltaX, 0);
				World = world * rotation;

So, the event will be fired, but its not doing anything unless you're actually setting the InteractionEnabled to true. I'm not quite getting the problem I think. (Sorry if I'm slow!)

Feb 2, 2011 at 9:23 PM

I guess I'm just saying that it's not as efficient as it could be, as far as I can tell.  I admit I need to learn more about the grand design before I start offering too many suggestions...

True, the performance inpact is minimal (whatever the performance hit is to call an event that immediately returns) since most applications that would use this feature that I can think of wouldn't have very many objects.  But it's creating a new delegate object (Event) for every Node instance (correct me if I'm wrong) for an purpose which would be rarely called outside of something like the SampleBrowser application, where it is ideally suited.

Now I have no idea how many Nodes there would be in a typical application, but it just seems to me that it would be cheaper, for the long-term sake of the engine, to either not use an Event or to allocate it only when needed.

Feb 3, 2011 at 4:19 PM

You've got a very valid point. I haven't really looked at the memory impact, nor the performance impact of this. I think for now there are bigger fish to fry within Balder, but completely agree with you on this that it would be more efficient doing it without the event handler like that. 

Feb 4, 2011 at 4:54 PM

Fair enough.  :)