///////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////////////////////////////////////
VECTOR ball_speed;
VECTOR modelRotate;
VECTOR statbilSys;
ENTITY* ball;
VECTOR temp;
VECTOR pos;
var camera_distance[3]= {-100,0,10};
var camera_angle[3];
var cam_dist[3] = {0,200,300}; // xyz distance vector from camera towards the target
var engineExhaustAnzahlPartikel = 10; //number of particles used for this effect
function vec_randomize (var* vec, var range);
function part_alphafade(PARTICLE *p);
function effect_smokes(PARTICLE *p);
function increase_roll();
function decrease_roll();
BMAP* particle_map;
particle_map = bmap_create("particle.pcx");
preload_mode = 3;
function main()
{
video_switch (8,32,2);
level_load("roller.wmb"); // load the level
wait (2); // wait until the level is loaded
ball = ent_create ("fighter1.mdl", vector(-400, 0, 100), NULL); // create the ball
modelRotate.x = 90;
modelRotate.y = 180;
modelRotate.z = -90;
c_rotate(ball, modelRotate,USE_AXISR);
wait(1); // wait 1 frame after creation
c_updatehull(ball,0);
ph_setgravity (vector(0, 0, 0)); // set the gravity
phent_settype (ball, PH_RIGID, PH_BOX); // set the physics entity type
phent_setmass (ball, 3, PH_BOX); // and its mass
phent_setfriction (ball, 80); // set the friction
phent_setdamping (ball, 40, 40); // set the damping
phent_setelasticity (ball, 2, 20); // set the elasticity
sky_color.red = 0;
sky_color.green = 0;
sky_color.blue = 15;
while (1)
{
ball_speed.x = 0; // move the ball using the cursor keys
ball_speed.z = -200 * (key_cuu - key_cud); // 25 sets the x / y movement speeds
modelRotate.y = 5 * (key_cul - key_cur); // no need to move on the vertical axis
//VECTOR outVel;
//phent_getangvelocity (ball, outVel);
modelRotate.x = 0;
modelRotate.z = 0;
ball.z = 300;
ball.tilt = 0;
//ball.roll = 90;
//phent_addvelcentral (ball, ball_speed); // add a torque (an angular force) to the ball
phent_addforcelocal(ball,ball_speed, vector(0,0,0));
phent_addtorquelocal ( ball, modelRotate );
my = ball; // The target Entity
// calculate the camera view's direction angle to the target
ANGLE cam_ang[3]; // direction angle of the camera to the target.
vec_diff(temp,nullvector,cam_dist);
vec_to_angle(cam_ang,temp);
cam_ang.roll = 0; // roll didn't change vec_to_angle
// place the camera at the right position to the target
vec_set(camera.x,cam_dist);
vec_rotate(camera.x,my.pan);
vec_add(camera.x,my.x);
//vec_add(camera.x,shipVel.z);
// Set the camera angles to the camera view direction
vec_set(camera.pan,cam_ang);
// and rotate it about the target angle
ang_add(camera.pan,my.pan);
//ang_add(camera.pan, add_pan.pan);
camera.roll = 360;
if (key_cuu) {
VECTOR particles_right, particles_dir;
vec_for_vertex(particles_right, ball, 1753);
//only one particles_dir needed per ship, same for all engines
//
vec_set(particles_dir, vector(-5,2,2)); // length of spray
// tweak the -10,0,0 to get the look you want, maybe size to thrust % if there is one
vec_rotate(particles_dir, ball.pan); // rotate to match ship rotation
effect(effect_smokes,15,particles_right,particles_dir);
//increase_roll();
}else{
//decrease_roll();
}
wait (1);
}
}
//// Particle movement handling ///////
function vec_randomize (var* vec, var range)
{
vec[0] = random(0.5) - 0.25;
vec[1] = random(0.5) - 0.25;
vec[2] = random(1) - 0.25;
vec_normalize(vec,random(range));
}
//// particle alpha handling ////////
function part_alphafade(PARTICLE *p)
{
p.alpha -= 20*time_step;
if (p.alpha <= 0) p.lifespan = 0;
}
///// particle creating /////////
function effect_smokes(PARTICLE *p)
{
p.blue = 46.191;
p.green = 86.840;
p.red = 253.129;
var temp[3];
vec_randomize(temp,3);
vec_inverse(temp);
vec_add (p.vel_x, temp);
p.size = 2.770 ;
p.alpha = 50 ;
p.gravity = 0 ;
p.alpha = 50 + random(15);
p.bmap = particle_map;
p.flags |= (MOVE | BRIGHT | BEAM | TRANSLUCENT);
p.event = part_alphafade; // change to a shorter, faster function
}
function increase_roll()
{
while (ball.roll <= (25+90)) {
ball.roll += 0.01;
}
}
function decrease_roll()
{
while (ball.roll > 95) {
ball.roll -= 0.01;
}
}