Camera zoom based on entity movement

All things HTML5 or text based engines, or really any web based engines.
Post Reply
robaldred
Posts: 64
Joined: Tue Aug 27, 2013 5:54 pm

Camera zoom based on entity movement

Post by robaldred »

I want to zoom the camera out depending on how fast an entity is moving. I thought I had it working, but the following raises a Matrix NaN error.

To start with I was just trying to zoom the camera out by scaleTo .5 but I want to do this gradually so I'm tweening it...

Code: Select all

#coffeescript
ige.client.viewport.camera._scale.tween()
	.stopAll()
	.stepTo(
	    x: ige.client._baseScale * .5
	    y: ige.client._baseScale * .5
	    z: ige.client._baseScale * .5
	)
	.duration(1000)
	.start()

       // base scale is just a value I've set on the client eg. 1.5
This raises the following error:

Code: Select all

Uncaught IGE *error* [IgeScene2d:uiScene] : The matrix operation produced a NaN value! IgeClass.js:96
log IgeClass.js:96
IgeMatrix2d.transformCoord IgeMatrix2d.js:34
IgeMatrix2d.transform IgeMatrix2d.js:68
IgeObject.extend.localToWorld IgeEntity.js:979
IgeObject.extend.aabb IgeEntity.js:1078
IgeObject.extend.update IgeEntity.js:1557
IgeEntity.extend.update IgeScene2d.js:110
IgeEventingClass.extend.update IgeObject.js:1428
IgeObject.extend.update IgeEntity.js:1569
IgeEntity.extend.update IgeScene2d.js:110
IgeEntity.extend.update IgeViewport.js:134
IgeEntity.extend.updateSceneGraph IgeEngine.js:1950
IgeEntity.extend.engineStep IgeEngine.js:1881
Any idea, what's going on?

If I just do...

Code: Select all

s = ige.client._baseScale * .5
ige.client.viewport.camera.scaleTo(s,s,s)
It works fine, but it's too aggressive as it snaps straight to the zoom level, so that's why I wanted to tween it.
Last edited by robaldred on Tue Sep 17, 2013 3:52 pm, edited 1 time in total.
robaldred
Posts: 64
Joined: Tue Aug 27, 2013 5:54 pm

Re: Camera zoom based on entity movement

Post by robaldred »

I have it working with a third party tweening framework TweenMax

Code: Select all

# coffeescript
TweenMax.to @, 1,
	_cameraScale: ige.client._baseScale * .5
	onUpdateParams: [@]
	onUpdate: (self) ->
		s = self._cameraScale.toFixed(2)
		ige.client.viewport.camera.scaleTo(s,s,s)
User avatar
coolbloke1324
Posts: 181
Joined: Mon Jan 23, 2012 5:20 pm

Re: Camera zoom based on entity movement

Post by coolbloke1324 »

robaldred wrote:I want to zoom the camera out depending on how fast an entity is moving. I thought I had it working, but the following raises a Matrix NaN error.

To start with I was just trying to zoom the camera out by scaleTo .5 but I want to do this gradually so I'm tweening it...

Code: Select all

#coffeescript
ige.client.viewport.camera._scale.tween()
	.stopAll()
	.stepTo(
	    x: ige.client._baseScale * .5
	    y: ige.client._baseScale * .5
	    z: ige.client._baseScale * .5
	)
	.duration(1000)
	.start()

       // base scale is just a value I've set on the client eg. 1.5
This raises the following error:

Code: Select all

Uncaught IGE *error* [IgeScene2d:uiScene] : The matrix operation produced a NaN value! IgeClass.js:96
log IgeClass.js:96
IgeMatrix2d.transformCoord IgeMatrix2d.js:34
IgeMatrix2d.transform IgeMatrix2d.js:68
IgeObject.extend.localToWorld IgeEntity.js:979
IgeObject.extend.aabb IgeEntity.js:1078
IgeObject.extend.update IgeEntity.js:1557
IgeEntity.extend.update IgeScene2d.js:110
IgeEventingClass.extend.update IgeObject.js:1428
IgeObject.extend.update IgeEntity.js:1569
IgeEntity.extend.update IgeScene2d.js:110
IgeEntity.extend.update IgeViewport.js:134
IgeEntity.extend.updateSceneGraph IgeEngine.js:1950
IgeEntity.extend.engineStep IgeEngine.js:1881
Any idea, what's going on?

If I just do...

Code: Select all

s = ige.client._baseScale * .5
ige.client.viewport.camera.scaleTo(s,s,s)
It works fine, but it's too aggressive as it snaps straight to the zoom level, so that's why I wanted to tween it.
That is really odd. The matrix NaN error usually gets fired when something in the maths is wonky and some value is used that is not a number or divides by zero or something. Would love to get to the bottom of this one as obviously should work.

The tweening is one of the oldest parts of the engine because it has "just worked" for quite some time so it's likely to be something else that has changed recently like IgePoint class or something.
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
User avatar
coolbloke1324
Posts: 181
Joined: Mon Jan 23, 2012 5:20 pm

Re: Camera zoom based on entity movement

Post by coolbloke1324 »

Just a thought but it could also be if the engine has not been started yet since it uses engine timing to generate tweening and if the engine hasn't started it could go wonky from that...
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
Post Reply

Return to “HTML5/Web Engines”