Game Development Community

Camera Control Functions

by Jeff Peck · in General Discussion · 11/15/2002 (6:50 am) · 1 replies

Well fellows, in my work on the cinema editor, I've completed a couple functions you might find handy... please, use them for whatever you want and get back to me with any bugs (I can usually be found in the GG IRC chat, and I'll respond pretty quickly usually)

Anywho, these first two are for file creation:

function CreateFile()
{
   //Determine the file name
   %filename = $Editor::Filename;
   //Point it to the directory
   %file = $Editor::SaveFolder @ %filename @ ".cs";
   
   $Editor::CurrentFile = %file;

   new fileobject("File");

   if(isFile(%file))
     	File.openForAppend(%file); //if the file exists, append the next line
   else
     	File.openForWrite(%file);  //if it doesn't, create it

   //good housekeeping
   File.Close();
   File.Delete();
}

And:

function WriteLine(%line)
{
   new fileobject("File");
   %file = $Editor::CurrentFile;

   if(isFile(%file)) //this should always be the case
      File.openForAppend(%file);
   else
      error("File not pre-created, create a file first");
  
   File.WriteLine(%line);
   File.Close();
   File.Delete();
}

and these next three (my pride and joy!) are for messing with peoples cameras.

function servercmdattachcamera(%client, %object)
{
    %control = %client.getControlObject();

    if (%control == %client.player) // If the client isn't floating around already, set him to control camera mode
    {
       %control = %client.camera;
       %control.mode = toggleCameraFly;
       %client.setControlObject(%control);
    }

    %OTransform = %object.GetTransform(); //Get the transform of the object to attach to
    %camera = %client.camera;
    %camera.settransform(%OTransform); //Send the client to the point!
}

function serversideattachcamera(%client, %object)
{
    %control = %client.getControlObject();

    if (%control == %client.player) // If the client isn't floating around already, set him to control camera mode
    {
       %control = %client.camera;
       %control.mode = toggleCameraFly;
       %client.setControlObject(%control);
    }

    %OTransform = %object.GetTransform(); //Get the transform of the object to attach to
    %camera = %client.camera;
    %camera.settransform(%OTransform); //Send the client to the point!
}

function attachallcameras(%object)
{
   for (%i = 0 ; %i < ClientGroup.getCount(); %i++)
   {
      %client = ClientGroup.getObject(%i);
      if (isObject(%client))
      {
         serversideattachcamera(%client, %object);
      }
   }
}

Now, just so you know (incase you don't, since it took me half an hour to figure this out last night) the proper way to pass an object into one of these functions is with objectname.getID()

EG: attachallcameras(campoint.getID()); or commandtoserver('attachcamera',campoint.getID()); (%client automatically gets passed to the called function when you use commandtoserver)

a bug (with the EDITOR, not my code) is that when you drop in a marker, even if you use "Drop at camera w/ rotation" it won't rotate it... when you attach the camera to the marker, you will be viewing down the Y axis, so just aim the Y axis at whatever you want to view and you'll be set.

I will be updating these functions soon because at the moment (for the camera control ones, at least) the camera is fully controllable once moved, which kinda defeats the purpose!

Anyway, enjoy!
~Jeff

#1
11/15/2002 (9:27 am)
Yum. I like. I'm not sure if I'll end up using this in my initial design, but this is definitely a valuable bit of information.

Why don't you submit it as a resource? ;)

- Tra'Hari