I’ve been using a 3D orthogonal camera thus far and have recently implemented spine animations. These animations have issues when my camera zooms and I suspect it has to do with the way I am zooming my camera rather than the spine animations.
You can see yourself how the animated characters become warped when I use camera zooming. Everything else behaves as expected:
For zooming, I just multiply the view matrix by a zoom scale matrix. Someone told me recently that this isn’t the correct way to do it:
return Matrix.CreateLookAt(cameraPosition, cameraLookAt, -up) * Matrix.CreateScale(Zoom);
I created my Orthogonal camera projection like this:
Projection = Matrix.CreateOrthographic(ScreenWidth/100f, ScreenHeight/100f, 0.0f, 4000.0f);
I have no idea why that’s happening, but that is an extremely solid music choice, lol!
I’ve seen this type of thing happen when I’ve done 2D zoom before, usually when I don’t apply scaling in a consistent way, but I’m not sure why that would happen in a 3D scene. Do you do any scaling or transformation on that character that takes into consideration the camera position?
You might investigate your animation implementation, since everything else seems to zoom correctly.
In terms of position, how far away from the background is your sprite? Also, try zoom * lookat instead if lookat * zoom. I’m pretty sure the order matters. I’m just speculating on what the problem might be, so I might be way off.
It looks like it’s changing the width of the sprite and not really the height. Or maybe the height but just a tiny bit.
The camera is implemented the same way it is for my other 3D objects.
Something close to:
basicEffect.Parameters["MatrixTransform"].SetValue(cameraView * cameraProjection);
The camera works perfectly regarding these spine animations for everything else. Just not zoom.
The sprite here is drawn at 0,0,0. I tried switching up the multiplication but that didn’t work.
Shouldn’t I be “zooming” by simply changing the camera’s position? Isn’t there a formula where, given the camera’s position and rotation, where would it be if It went in that direction? Isn’t that the “forward vector”? I’m now attempting to multiply the View.Forward of the camera. But that’s not working correctly.
It makes sense to me that “zooming” should be achieved simply by changing the position of the camera. Like if a camera is rotated to point at (0,0,0) and it’s position is (0,0,10). Then zooming in 50% would just change its position to (0,0,5). If the rotation was something else that would require some trig function to figure out right?
Yea that’s what’s making me wonder if there’s something going on inside the animation code that maybe takes some properties of the camera into consideration. I don’t do a lot of 3D stuff but…
… this is what I would expect as well. If your sprite is rendered via a textured quad, it definitely should not distort simply because you moved the camera closer.
Since everything else in your scene remains static, it makes me think there’s something in how your sprites are being drawn. In fact, it almost looks like the camera for the room is orthographic, but the camera for the sprites is perspective. Which, based on what you’ve said so far, doesn’t make sense.
Oh another thing, is there a shader involved in how the sprites are drawn?
(Again, I don’t have a lot of experience here, just throwing out ideas for you to debug. Basically, being your rubber duck :D)
The problem sprites are drawn using Esoteric’s Spine animation system. So it’s possible there is something going on in those runtime files that causes them to behave differently somehow. I’m not sure what it could be since these animations look fine on all other camera behaviors. I’m not sure why Zoom would be an issue. I have other quads or planes in the scene that behave normally. I have posted this problem on Esoteric’s forums.
Nevermind for now. I have realized this zoom issue is related to my billboarding. I need to reinvestigate how that is done.
1 Like
Okay, I figured it out. There is a reason the animation was being misplaced and another reason it was having problems zooming.
The zooming problem came from the following. This is for billboarding.
ModelMatrix.Right = new Vector3(References._3Dcamera.ViewNoScale.Forward.Z, 0, References._3Dcamera.View.Forward.X);
And then later
var MVP_Matrix = ModelMatrix * References._3Dcamera.View * References._3Dcamera.Projection;
The problem is that camera.View contains the zoom/scale multiplier:
return Matrix.CreateLookAt(cameraPosition, cameraLookAt, -up) * Matrix.CreateScale(Zoom);
So by invoking it twice it was creating an issue.
Sorry for taking us down the wrong path. Still curious if zoom can be obtained by a trig formula that changes camera position.
2 Likes