Game Development Community

100 Bounty - Camera transform to mission area

by Peter Simard · in Torque Game Engine · 08/24/2007 (12:02 pm) · 12 replies

$100 paypal to the first person to submit this to me. It can either be submitted publicly or, via email (petesimard@rampid.com).

Requirements

-Create a consoleMethod "missionAreaCam()"
-Function will transform the free camera to view the entire contents of the map. With the camera facing straight down. The camera will be positioned in the center of the mission area.
-It will need to calculate the view fulstrom so that the camera will view the largest extent of the mission area (x or y).

The goal is to get a view of the entire mission with the extent of the view constrained exactly to largest axis of the mission area. This will be used for auto-generating mini-maps.

#1
08/24/2007 (12:44 pm)
You may want to look at this (for free!): http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5277
#2
08/24/2007 (1:59 pm)
Thanks, there is some good info in there but not exactly what I need. Maybe someone can go through it and make this resource with the help of that post.
#3
08/26/2007 (2:26 pm)
Bounty is now $75
#4
08/26/2007 (5:11 pm)
Peter,

Have you checked out the RTS kit and it's minimap?
Edit: Alright. Nevermind then.
#5
08/26/2007 (5:18 pm)
Do you mean something like this? Click here where in our game we use the camera above on a mini-map, and when you walk the camera walks with you ?
#6
08/26/2007 (5:22 pm)
Getting the camera to face the ground isn't the issue. It's calculating the view fulstrom of the camera, so that it is exactly high enough off the ground to show the full extent of the mission area. It needs to be exact.
#7
08/26/2007 (6:59 pm)
You do realize that this is early high school geometry?

You're solving for the height of an isosceles triangle that is derived from the triangle created by the distance between the two edges of your mission area that are the furthest apart and the angle that is the degree of your field of vision in the frustrum, then chopping everything in half to make it easier to solve for height, and applying some sohcahtoa magic. You'd probably go a smidge higher than that so that perspective doesn't cut off anyone's heads.

Unless you're using orthographic projection. In which case, smack yourself.
#8
09/01/2007 (11:56 am)
Bounty is now $100.
#9
09/03/2007 (2:54 pm)
Here is a possible solution:

The majority of this is done in script, with one very small modification to the camera code.

There are a few limitations:
Hard-coded for a 4:3 aspect ratio. (See $Aspect)
There is some small padding on the limiting dimension, which can be corrected manually, by I can't find a mathematical reason for it (Mathematical model != results).

It works by creating a camera centered on the mission area object (pointing down) at a height which allows for a full viewing of the mission area (The height is based on the dimensions of the mission area, and the camera's FOV). It uses the surface of the water block to define base ground level. Camera FOV is copied from the current camera.

The included keybind is 'm'.

Code
in Camera.cc
change
#define MaxPitch 1.3962
to
#define MaxPitch 1.5708

This will allow the camera to point straight down!

Scripts
Add to server/commands.cs
//Mission Camera by Gabriel Notman
//Limitations
//Water block must be called 'Water'
//Mission area object must be called 'MissionArea'
//Cam with 4/3 aspect ration
$Aspect=4/3;

//Turns off fog
//Sets view distnace to maximum
function MaxView(%on)
{
   if (%on)
   {
      //save values
      $fogDistance=sky.fogDistance;
      $viewDistance=sky.visibleDistance;
      
      //set values 
      //2k max for visible distance
      //if not enough must change code
      sky.fogDistance=20000; //far far away
      sky.visibleDistance=2000;
      
      //force client update
      sky.applySkyChanges();
   }
   else
   {
      //Set original values
      sky.fogDistance=$fogDistance;
      sky.visibleDistance=$viewDistance;
      
      //force client update
      sky.applySkyChanges();
   }
}

//Calculates the floor height
//Uses 'sea level' the height of the water block surface
function calculateFloorHeight()
{
   %height=getWord(water.position, 2)+getWord(water.scale, 2);
   
   return %height;
}

function calculateHeight(%viewAng, %dim)
{
   %height=(%dim/2)/mTan(mDegToRad(%viewAng));
   
   return %height+calculateFloorHeight();
}

function createMisCam(%fov)
{
   %area=MissionArea.getArea();
      
   %width=getWord(%area, 2);
   %height=getWord(%area, 3);
   
   %x=getWord(%area, 0) + %width/2;
   %y=getWord(%area, 1) + %height/2;
   %z=0;
   
   if ((%width*$Aspect)>%height)
      %z=calculateHeight(%fov/2 * 1/$Aspect, %width);
   else
      %z=calculateHeight(%fov/2, %height);
      
   %orientation=matrixCreateFromEuler(mDegToRad(270) SPC "0 0");
   %orientation=getWords(%orientation, 3, 6);
      
   %cam=new Camera() {
      dataBlock = Observer;
   };
       
   %cam.setTransform(%x SPC %y SPC %z SPC %orientation);
   %cam.setCameraFov(%fov);
   
   return %cam;
}

function serverCmdToggleMissionCam(%client)
{
   %cam=%client.camera;
   
   %control = %client.getControlObject();
   if (%control == %client.player)
   {
      %control.mode = toggleCameraFly;
      
      $MisCam=createMisCam(%cam.getCameraFov());
      
      %control=$MisCam;
                 
      MaxView(true);
   }
   else
   {
      %control = %client.player;
      
      echo($MisCam.getTransform());
            
      %control.mode = observerFly;
      
      if (isObject($MisCam))
         $MisCam.delete();
      
      MaxView(false);
   }
   %client.setControlObject(%control);
}

Add to client/config.cs (map to a key)
moveMap.bind(keyboard, "m", toggleMissionCamera);

Add to client/scripts/default.bind.cs
function toggleMissionCamera(%val)
{
   if (%val)
      commandToServer('ToggleMissionCam');
}
moveMap.bind(keyboard, "m", toggleMissionCamera);

Let me know if its sufficient.

Gabriel
#10
09/03/2007 (3:29 pm)
Thanks Gabriel! I think this will work out nicely. If you send me your paypal address I will send you the bounty.
#11
09/03/2007 (3:31 pm)
Its gn2ect@bolton.ac.uk

Gabe
#12
09/03/2007 (4:23 pm)
Thank you, received it fine.

Gabriel