Kamere

1. 3rd, Orbit and 1st camera
2. Dugeon Siege camera
3. Zelda 64 camera style


3rd person, Orbit i 1st person kamere

var oko_kamere = 1; //ovo se koristi za podesavanje visine oka kamere)
var centar_kamere[3]; 
var pozicija_kamere[3]; 
var trejs_pozicija[3]; 
var trejs_distanca;
var kamera_mod = 1; // 1 za 3rd, 2 za Orbit i 3 za 1st person
var fade_start = 45;
var fade_kraj = 15;
var distanca_kamere = 140; //od igraca
var orbit_kamera_distanca; 
var orbit_kamera_pan;
var orbit_kamera_tilt;

view camera_orbit
{
layer = 2;
}

view camera_1st
{
layer = 3;
}

function PromeniKameru()
{
kamera_mod %= 3;
kamera_mod += 1;
}

function 3rd_kamera()
{
camera.diameter = 0; // napravi kamera passable
camera.genius = null;
vec_set(centar_kamere.x,player.x);
centar_kamere.z += (player.max_z * oko_kamere);
orbit_kamera_pan = player.pan;
orbit_kamera_distanca = cos(orbit_kamera_tilt)*distanca_kamere;
pozicija_kamere.x = centar_kamere.x - cos(orbit_kamera_pan)*orbit_kamera_distanca;
pozicija_kamere.y = centar_kamere.y - sin(orbit_kamera_pan)*orbit_kamera_distanca;
pozicija_kamere.z = centar_kamere.z + sin(orbit_kamera_tilt)*distanca_kamere;
trejs_distanca = cos(orbit_kamera_tilt)*(distanca_kamere + 40);
trejs_pozicija.x = centar_kamere.x - cos(orbit_kamera_pan)*trejs_distanca;
trejs_pozicija.y = centar_kamere.y - sin(orbit_kamera_pan)*trejs_distanca;
trejs_pozicija.z = centar_kamere.z + sin(orbit_kamera_tilt)*(distanca_kamere + 40);
camera.pan = orbit_kamera_pan;
camera.roll = 0; //bez rolovanja
camera.tilt = -orbit_kamera_tilt;
orbit_kamera_tilt = clamp(orbit_kamera_tilt, -45, 90);

c_trace(centar_kamere.x, trejs_pozicija.x,(ignore_me + ignore_passable + ignore_passents));
if(trace_hit == 1)//ako igrac udari u nesto pomeri kameru napred
{
vec_diff(temp.x,trejs_pozicija.x,target.x);
vec_diff(pozicija_kamere.x,pozicija_kamere.x,temp.x);
// malo preciznija kamera pri tom da je camera clip near 1 da ne prolazi kroz zidove
// oseti se kod prolaza kroz vrata i na uskom prostoru
vec_set(pozicija_kamere.x,target.x);
vec_normalize(normal.x, (camera.clip_near/2) );
vec_add(pozicija_kamere.x,normal.x);
}

if(fade_start > 0)
{
if(player != NULL) 
{
temp.x = vec_dist(centar_kamere.x, pozicija_kamere.x); 
if(temp.x > fade_start)
{
player.transparent = off; 
}
else
{
player.transparent = on;
player.alpha = 100 * max(0,((temp.x - fade_kraj) / max(1,(fade_start - fade_kraj))));
}
}
}
vec_set(camera.x,pozicija_kamere.x);
}
}

function orbit_kamera()
{
camera_orbit.diameter = 0; // napreavi prolaznost kamere na 1
camera_orbit.genius = null;
vec_set(centar_kamere.x,player.x);
centar_kamere.z += (player.max_z * oko_kamere);
orbit_kamera_pan += 4 * (key_cul - key_cur) * time;
orbit_kamera_distanca = cos(orbit_kamera_tilt)*distanca_kamere;
pozicija_kamere.x = centar_kamere.x - cos(orbit_kamera_pan)*orbit_kamera_distanca;
pozicija_kamere.y = centar_kamere.y - sin(orbit_kamera_pan)*orbit_kamera_distanca;
pozicija_kamere.z = centar_kamere.z + sin(orbit_kamera_tilt)*distanca_kamere;
trejs_distanca = cos(orbit_kamera_tilt)*(distanca_kamere + 40);
trejs_pozicija.x = centar_kamere.x - cos(orbit_kamera_pan)*trejs_distanca;
trejs_pozicija.y = centar_kamere.y - sin(orbit_kamera_pan)*trejs_distanca;
trejs_pozicija.z = centar_kamere.z + sin(orbit_kamera_tilt)*(distanca_kamere + 40);
camera_orbit.pan = orbit_kamera_pan;
camera_orbit.roll = 0; //bez rolovanja
camera_orbit.tilt = -orbit_kamera_tilt;
orbit_kamera_pan = orbit_kamera % 360; //maksimum 360 stepeni
orbit_kamera_tilt = clamp(orbit_kamera_tilt, -45, 90);

c_trace(centar_kamere.x, trejs_pozicija.x,(ignore_me + ignore_passable + ignore_passents));
if(trace_hit == 1) // trace ako udari u nesto
{

vec_diff(temp.x,trejs_pozicija.x,target.x);
vec_diff(pozicija_kamere.x,pozicija_kamere.x,temp.x);
}

if(fade_start > 0)
{
if(player != NULL) 
{
temp.x = vec_dist(centar_kamere.x, pozicija_kamere.x); 
if(temp.x > fade_start)
{
player.transparent = OFF; // providnost igraca
}
else
{
player.transparent = ON; // kada je blizu bloka
player.alpha = 100 * max(0,((temp.x - fade_kraj) / max(1,(fade_start - fade_kraj))));
}
}
}
vec_set(camera_orbit.x,pozicija_kamere.x);
}
}

function 1st_person_kamera() 
{ 
camera_1st.genius = player; //iskljuci ako zelis da vidis playera u prvom licu
vec_set(camera_1st.x,player.x); 
camera_1st.y = player.y;
camera_1st.z = player.z + 95; 
camera_1st.tilt += 10 * mouse_force.y * time;
camera_1st.pan = player.pan; 
}

function BoboKamera() // Ovo ide u function main za koriscenje kamere
{
while(1)
{
if (kamera_mod == 1)
{
camera_orbit.visible = off;
camera_1st.visible = off;
camera.visible = on;
3rd_kamera();
distanca_kamere -= mickey.z * 0.5 * time; 
distanca_kamere = clamp(distanca_kamere,80,600);
}
if (kamera_mod == 2)
{
camera.visible = off;
camera_1st.visible = off;
camera_orbit.visible = on;
orbit_kamera();
distanca_kamere -= mickey.z * 0.5 * time; 
distanca_kamere = clamp(distanca_kamere,80,600);
}
if (kamera_mod == 3)
{
camera.visible = off;
camera_orbit.visible = off;
camera_1st.visible = on;
1st_person_kamera();
}
wait(1);
}
} 

on_k = PromeniKameru;


Dugeon Siege kamera


//RPG Isometric kamera:
//- Nevidljive rupe
//- Zumiranje kamere
//- Kamera se rotira 360* oko igraca
//////////////////////////////////////////////////////////////////////////// 

ACTION nevidljiva_rupa {
MY.ENABLE_SHOOT = ON;
SET MY.EVENT,roof_event;
while 500 {
MY.INVISIBLE = OFF; 
wait 500; } 
} 
function roof_event{
if (event_type == EVENT_SHOOT)
{
MY.INVISIBLE = ON;
}
else
{
MY.INVISIBLE = OFF;
}
}
////////////////////////////////////////////////////////////////////////////
//Isometric kamera pogled
var spin_angle = 45; 
function move_view_3rd()
{

CAMERA.DIAMETER = 0; // napravi prolaznost kamere
CAMERA.genius = player;

CAMERA.Z = player.z + 300; 

WHILE 1 {

CAMERA.X = player.x + 282.8*cos(spin_angle); 
CAMERA.Y = player.y + 282.8*sin(spin_angle); 
vec_set(temp,player.x);
vec_sub(temp,camera.x); // temp = player - kamera
vec_to_angle(camera.pan,temp); 

IF (spin_angle > 359) {
spin_angle = 0;
}

WAIT 1;

person_3rd = 1; 
zoom_camera(); //Napravi nevidljive sve entitete (roofs)
WHILE 1 {
SHOOT CAMERA.POS,PLAYER.POS;
wait (1); }
}
} 
function zoom_camera {
WHILE (KEY_O == 1) { // Pritisni O
CAMERA.ARC -= TIME / 8;
IF (CAMERA.ARC <= 10) {
CAMERA.ARC = 10;
}
WAIT 1;
}
WHILE (KEY_P == 1) { // Pritisni P
CAMERA.ARC += TIME / 8; // Zoom out
IF (CAMERA.ARC >= 60) {
CAMERA.ARC = 60;
}
WAIT 1;
}
} 
function swing_camera {
WHILE (KEY_Y == 1) { // Press y 
spin_angle = spin_angle - .1;
WAIT 1; 
}
WHILE (KEY_U == 1) { // Press y 
spin_angle = spin_angle + .1;
WAIT 1; 
}

} 

Zelda 64 kamera stil


var force[3];
var friction;
var dist[3];
var cam_mem[3];
var camera_dist;
var cam_dist_trace;
var player_height;
var cam_ground_dif; //camera-ground differenz
var camera_player_high_dif;

// Animacija igraca
function player_animation() 
{
if (force.y == 0) 
{
ent_cycle("stand", my.skill47);
my.skill47 += 2 * time;
if(my.skill47 > 100) 
{ 
my.skill47 = 0;
}
}

if (key_cuu == 1) 
{
ent_cycle("walk", my.skill48);
my.skill48 += 5 * time;
if (my.skill48 > 100) 
{
my.skill48 = 0;
}
}

if(key_cud == 1) 
{
ent_cycle("walk", my.skill48);
my.skill48 -= 5 * time;
if (my.skill48 < 0) 
{
my.skill48 = 100;
}
}

if (force.x == 0 && key_cul == 1) 
{
ent_cycle("walk", my.skill47);
my.skill47 += 5 * time;
if (my.skill47 > 100) 
{ 
my.skill47 = 0;
}
}

if (force.x == 0 && key_cur == 1) 
{
ent_cycle("walk", my.skill47);
my.skill47 += 5 * time;
if (my.skill47 > 100) 
{ 
my.skill47 = 0;
}
}
}

function camera_calculate() 
{ 
player_height = me.max_z - me.min_z; //playerhigh
camera_dist = vec_dist(my.x,camera.x); //distance player-camera
if (dist.x < 0) 
{ //if dist negativ
vec_inverse(dist.x); 
} //set to positiv
if (camera_dist > 3*player_height) 
{
cam_mem.x += dist.x * cos(camera.pan); //camera to player
cam_mem.y += dist.x * sin(camera.pan); 
}
if (camera_dist < 1*player_height) 
{
cam_mem.x -= dist.x * cos(camera.pan); //camera from player
cam_mem.y -= dist.x * sin(camera.pan);
}
cam_mem.z = camera.z; //cameramemory high = camera high
camera_link();
}

function camera_link () 
{
vec_set(temp,camera.x);
temp.z -= 4000;
trace_mode = ignore_me+ignore_passable+use_box;
cam_ground_dif = trace (camera.x,temp); //camera-ground differenz
camera_player_high_dif = player_height - cam_ground_dif;
camera.x = cam_mem.x;
camera.y = cam_mem.y;
cam_mem.z = camera.z + camera_player_high_dif -20;//hold camera over ground
if (camera.z < cam_mem.z) //cam old more deeply then cam new?
{ 
camera.z += time * 4; //reconciliation
} 
if (camera.z > cam_mem.z) //cam old higher then cam new?
{ 
camera.z -= time * 4; //reconciliation
} 
if (camera.z < my.z) //camera more deeply then player t.e. at the mountain ?
{
camera.z = my.z; //then camerahigh = playerhigh
}
vec_set (temp,me.x);
vec_sub (temp,camera.x);
vec_to_angle (camera.pan,temp); //camera show on player
trace_mode = ignore_me+ignore_passents+ignore_passable+use_box;
cam_dist_trace = trace (camera.x,my.x);
if (cam_dist_trace != 0) //camera-player no view?
{ 
cam_dist_trace -= 2*time;
camera_dist = cos(camera.tilt)* cam_dist_trace;
cam_mem.x = me.x - cos(camera.pan) * camera_dist;
cam_mem.y = me.y - sin(camera.pan) * camera_dist;
}
wait (1);
}


action player_move 
{
if(player == null) {player = me;}
while(1) 
{
force.pan = -10 * key_force.x; 
my.skill14 = time*force.pan + max(1-time*0.7,0)*my.skill14;
my.pan += time * my.skill14; 
vec_set(temp,my.x);
temp.z -= 4000;
trace_mode = ignore_me+ignore_sprites+ignore_models+ignore_passable+use_box;
result = trace(my.x,temp);
if (result > 5) 
{ // in der Luft?
force.x = 0; 
force.y = 0;
force.z = -5; 
friction = 0.1; 
} 
else 
{ // auf und nahe dem Boden
force.x = 10 * key_force.y; 
force.y = 0;
force.z = -0.5 * result; 
friction = 0.7;
}
my.skill11 = time*force.x + max(1-time*friction,0)*my.skill11;
my.skill13 = time*force.z + max(1-time*friction,0)*my.skill13;
dist.x = time * my.skill11; // Distanz vorwärts
dist.y = 0;
dist.z = time * my.skill13; 
move(my,dist,nullvector); 
player_animation();
camera_calculate(); 
wait(1);
}
} 
