1 registered members (henrybane),
1,246
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
Expert
|
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 smirk](/ubb7/images/graemlins/default_dark/smirk.gif) This has made it fairly robust and very flexible. ![cool cool](/ubb7/images/graemlins/default_dark/cool.gif) I think the built-in documentation should be sufficient. ![grin grin](/ubb7/images/graemlins/default_dark/grin.gif) If anyone has any questions feel free to ask, ![blush blush](/ubb7/images/graemlins/default_dark/blush.gif) and if you have any suggestions for improvements (that dont cripple flexibility) also PLEASE feel free. ![smile smile](/ubb7/images/graemlins/default_dark/smile.gif) I'll be buck..... ![cool cool](/ubb7/images/graemlins/default_dark/cool.gif) //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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 //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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
Member
|
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: EvilSOB]
#271271
06/12/09 06:25
06/12/09 06:25
|
Joined: Aug 2008
Posts: 153 Germany,Stuttgart
kwpsp
Member
|
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
OP
Expert
|
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
|
|
|
|