Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, NeoDumont), 761 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Camera rotation around a fixed (adjustable) point #221079
08/12/08 05:25
08/12/08 05:25
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I have seen this question many times across different forums,
and this piece of code has taken many of the suggestions into itself. smirk
This has made it fairly robust and very flexible. cool

I think the built-in documentation should be sufficient. grin

If anyone has any questions feel free to ask, blush
and if you have any suggestions for improvements (that dont cripple flexibility)
also PLEASE feel free. smile

I'll be buck..... cool


Code:
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Complete Camera Management function
//
VECTOR*   CamTarget =    { x=0; y=0; z=0; }   //Globally accesable Target of camera
VECTOR*   CamOffset =    { x=0; y=0; z=0; }   //Optionally global vector for the X,Y,Z Offset of Focus.  ie (0,0,0) = dead-on CamTarget
var       CamZoomFactor  = 50;                //Globally accesable ZOOM setting of camera
//
//
function Camera_Driver_startup()
{
   while(1)               
   {   
      //Optionally place limitations on available angles/positions
      camera.pan  = clamp(camera.pan, -175, 175);   //Limit possible Pan angle to keep Camera from Panning completely around
      camera.tilt = clamp(camera.tilt, -90, 0);     //Limit possible Tilt angle to keep Camera "above" play-field
      camera.roll = clamp(camera.roll, 0, 0);       //Limit possible Roll angle to disabled
      //
      //Position and Focus Camera
      camera.x = CamTarget.x + CamOffset.x - CamZoomFactor * cos(camera.tilt) * cos(camera.pan);
      camera.y = CamTarget.y + CamOffset.y - CamZoomFactor * cos(camera.tilt) * sin(camera.pan);
      camera.z = CamTarget.z + CamOffset.z - CamZoomFactor * sin(camera.tilt); 
      //
      //
      proc_mode = PROC_LATE;
      wait(1);         
   }
}
//
//
function Example_Camera_Controls_startup()
{
   VECTOR*   Offset = vector(0,0,0);
   while(1)               
   {   
      //Rotate/Zoom Camera
      if(key_pressed(280))   camera.pan    -= mickey.x/5;      // mouse movement left-right changes PAN       (when LeftClick held)
      if(key_pressed(280))   camera.tilt   -= mickey.y/5;      // mouse movement up-down    changes TILT    (when LeftClick held)
                             CamZoomFactor += mickey.z / 25;   // mouse Scroller up-down    changes ZOOM      (Anytime) 
      //
      //Change Positional Offset of Focus away from Target.  ie (0,0,0) = dead-on target
      if(key_pressed(72))   CamOffset.x      +=   time_step * CamZoomFactor / 25;      // Up  Arrow    Adjust 'North'
      if(key_pressed(80))   CamOffset.x      -=   time_step * CamZoomFactor / 25;      // Down Arrow   Adjust 'South' 
      if(key_pressed(75))   CamOffset.y      +=   time_step * CamZoomFactor / 25;      // Left Arrow   Adjust 'East'
      if(key_pressed(77))   CamOffset.y      -=   time_step * CamZoomFactor / 25;      // Right Arrow  Adjust 'West' 
      if(key_pressed(71))   CamOffset.z      +=   time_step * CamZoomFactor / 25;      // Home Key     Adjust Camera Height 'Up'
      if(key_pressed(79))   CamOffset.z      -=   time_step * CamZoomFactor / 25;      // End Key      Adjust Camera Height 'Down' 
      //
      //
      proc_mode = PROC_EARLY;
      wait(1);         
   }
}
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


[EDIT] THE NEWLY RELEASED (only slightly tested) C-SCRIPT Version
Code:
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Complete Camera Management function - C-SCRIPT VERSION !!
//
var CamTarget[3]  = 0,0,0;    //Globally accesable Target of camera
var CamOffset[3]  = 0,0,0;    //Optionally global vector for the X,Y,Z Offset of Focus.  ie (0,0,0) = dead-on CamTarget
var CamZoomFactor = 50;       //Globally accesable ZOOM setting of camera
//
//
starter Camera_Driver()
{
   while(1)               
   {   
      //Optionally place limitations on available angles/positions
      camera.pan  = clamp(camera.pan, -175, 175);   //Limit possible Pan angle to keep Camera from Panning completely around
      camera.tilt = clamp(camera.tilt, -90, 0);     //Limit possible Tilt angle to keep Camera "above" play-field
      camera.roll = clamp(camera.roll, 0, 0);       //Limit possible Roll angle to disabled
      //
      //Position and Focus Camera
      camera.x = CamTarget.x + CamOffset.x - CamZoomFactor * cos(camera.tilt) * cos(camera.pan);
      camera.y = CamTarget.y + CamOffset.y - CamZoomFactor * cos(camera.tilt) * sin(camera.pan);
      camera.z = CamTarget.z + CamOffset.z - CamZoomFactor * sin(camera.tilt); 
      //
      //
      proc_late();
      wait(1);         
   }
}
//
//
starter Example_Camera_Controls()
{
   var  Offset[3] = 0,0,0;
   while(1)               
   {   
      //Rotate/Zoom Camera
      if(key_pressed(280))  { camera.pan   -= mickey.x/5;   }  // mouse movement left-right changes PAN     (when LeftClick held)
      if(key_pressed(280))  { camera.tilt  -= mickey.y/5;   }  // mouse movement up-down    changes TILT    (when LeftClick held)
                             CamZoomFactor += mickey.z / 25;   // mouse Scroller up-down    changes ZOOM    (Anytime) 
      //
      //Change Positional Offset of Focus away from Target.  ie (0,0,0) = dead-on target
      if(key_pressed(72))  { CamOffset.x  +=   time_step * CamZoomFactor / 25; }  // Up  Arrow    Adjust 'North'
      if(key_pressed(80))  { CamOffset.x  -=   time_step * CamZoomFactor / 25; }  // Down Arrow   Adjust 'South' 
      if(key_pressed(75))  { CamOffset.y  +=   time_step * CamZoomFactor / 25; }  // Left Arrow   Adjust 'East'
      if(key_pressed(77))  { CamOffset.y  -=   time_step * CamZoomFactor / 25; }  // Right Arrow  Adjust 'West' 
      if(key_pressed(71))  { CamOffset.z  +=   time_step * CamZoomFactor / 25; }  // Home Key     Adjust Camera Height 'Up'
      if(key_pressed(79))  { CamOffset.z  -=   time_step * CamZoomFactor / 25; }  // End Key      Adjust Camera Height 'Down' 
      //
      //
      wait(1);         
   }
}
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Last edited by EvilSOB; 06/12/09 12:44.

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Camera rotation around a fixed (adjustable) point [Re: EvilSOB] #271267
06/12/09 05:59
06/12/09 05:59
Joined: Aug 2008
Posts: 153
Germany,Stuttgart
kwpsp Offline
Member
kwpsp  Offline
Member

Joined: Aug 2008
Posts: 153
Germany,Stuttgart
I test it in C-Script, it doesn't work, is there a C-Script version=?
thx
kwpsp


My system:
- Core 2 Quad 6600(4x 2,4GhZ)
- 2GB Ram
- GeForce 7050(:-))
- Windows seven
Re: Camera rotation around a fixed (adjustable) point [Re: kwpsp] #271270
06/12/09 06:17
06/12/09 06:17
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Just added a compiled but not live tested c-script version, please test for me wink


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Camera rotation around a fixed (adjustable) point [Re: EvilSOB] #271271
06/12/09 06:25
06/12/09 06:25
Joined: Aug 2008
Posts: 153
Germany,Stuttgart
kwpsp Offline
Member
kwpsp  Offline
Member

Joined: Aug 2008
Posts: 153
Germany,Stuttgart
:-(
< vec_fill(Offset[0],0)>
WORLD.wdl 95:0 Bad or missing parameter unknown function

It's great that you're supporting your posts ;-)
__________________________________________________
Besides I have a presentation on Monday about Australia,
maybe you could help me?

Last edited by kwpsp; 06/12/09 06:26.

My system:
- Core 2 Quad 6600(4x 2,4GhZ)
- 2GB Ram
- GeForce 7050(:-))
- Windows seven
Re: Camera rotation around a fixed (adjustable) point [Re: kwpsp] #271275
06/12/09 06:42
06/12/09 06:42
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
You mas be using OLD A7, or even A6. Hard for me to test.
Try changing that whole line to
var Offset[0] = 0,0,0;

Im at work now, so Ive only got a couple of hours left today, but I'll help
with your presentation if I can....
Im no great patriot, and its been 22 years since school...
So nothing TOO hard, please.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1