Game Development Community

SetTargetCameraArea

by Wes · in Torque Game Builder · 06/16/2008 (8:24 am) · 7 replies

1.7.3

before code:
SceneWindow2D.getCurrentCameraArea() == "-100.000000 -75.000000 100.000000 75.000000"

code:
%camTarget = SceneWindow2D.getCurrentCameraArea();
SceneWindow2D.setCurrentCameraArea($targetObject.getArea());
SceneWindow2D.setTargetCameraArea(%camTarget);
SceneWindow2D.setCameraInterpolationMode("LINEAR");
SceneWindow2D.startCameraMove(2);

after code:
SceneWindow2D.getCurrentCameraArea() == "-100.000000 -75.000000 101.000000 76.000000"

Why is this happening?

#1
06/16/2008 (5:45 pm)
Why are you getting the currentCameraArea and then reassigning if you aren't making any changes?

Could it be because you started a cameramove and so it is moving towards the target?
#2
06/16/2008 (6:19 pm)
Quote James Ford: "Why are you getting the currentCameraArea and then reassigning if you aren't making any changes?

Could it be because you started a cameramove and so it is moving towards the target?"

Read the code again James.

Line 1 gets the current camera area (in this case the entire screen) and saves it to the variable %camTarget.

Line 2 instantly sets the camera area to another area, in this case the area of a t2dStaticSprite (represented by $targetObject), which is much smaller that the original area. The actual camera area is now "-12.50000 -12.50000 12.50000 12.50000".

Line 3 sets a target area of %camTarget, which is the original (fullscreen) area.

Line 4 sets the interpolation mode, in this case to LINEAR, but I get the same results with SIGMOID.

Line 5 initiates the camera move to the new area, which is the original area set to the %camTarget variable, but, as I stated, it is moving the camera 1 unit off in the x and y dimensions.

I'm new here, but I'm a little surprised that I need to explain the code. I would have thought this to be fairly basic to TGB.
#3
06/16/2008 (7:42 pm)
Looking at the reference docs, it looks like getCurrentCameraArea returns "xMin yMin xMax yMax", whereas setTargetCameraArea takes "x y width height".

I could explain the reason I was confused given only your initial post, but in summary, looking at someone else's code is never easy.
#4
06/16/2008 (9:12 pm)
Quote James Ford: "Looking at the reference docs, it looks like getCurrentCameraArea returns "xMin yMin xMax yMax", whereas setTargetCameraArea takes "x y width height"."

That's a very good point, and I was a little confused by that at first as well. However, if it actually worked like that then the final area would be "-100.000000 -75.000000 0.000000 0.000000". So I'm guessing that it's just a misprint in the documents.

I still haven't been able to figure out why an extra unit is being added to the width and height. I can obviously write a function that makes corrections to the area, but that seems like a sloppy way of doing things.

I haven't gotten around to browsing the source code of the engine yet. Does someone know where I can find the methods that control camera movement?
#5
06/17/2008 (8:50 am)
T2dSceneWindow.h / .cpp
#6
06/17/2008 (9:59 am)
So I guess it comes down to this line:
object->setTargetCameraArea( RectF(topLeft.mX, topLeft.mY, bottomRight.mX-topLeft.mX+1, bottomRight.mY-topLeft.mY+1) );

Why the +1s?
#7
06/17/2008 (10:24 am)
That looks unnecessary to me. Perhaps a GG employee can chime in and/or add a bug log.