4 registered members (dBc, clonman, TipmyPip, 1 invisible),
18,936
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Problem with my beam effect
#442694
06/30/14 01:34
06/30/14 01:34
|
Joined: May 2014
Posts: 179 The lit part of the Truth
CyberGhost
OP
Member
|
OP
Member
Joined: May 2014
Posts: 179
The lit part of the Truth
|
I am testing a particle beam effect for a rocket trail (u may already know from my previous thread). I set vel_x/y/z to a vector handling the difference between rocket's position before and after its c_move() call (which normally controls its behaviour through arrow keys). Then, I checked if any of vel_x/y/z doesn't equal zero (which means that the rocket is moving) ,and if so, I randomize the vel_x/y/z vector by vec_randomize(). I use this image as a bmap for the effect: Download link: http://www.datafilehost.com/d/48c7bd08The problem is that: the particle doesn't look any good. It looks like cut strips or thin arcs (which is weird for a rocket trail). When I comment out vec_randomize() instruction, it doesn't look good either. It looks like the previous case. It takes the form of cut strips moving behind the rocket. Here are some screenshots: 1) If vec_randomize() is executed: 2) If vec_randomize() is commented out: So, what am I doing wrong? Here's my code (Note that I don't use BRIGHT flag):
BMAP* smoke = "smoke.tga";
VECTOR dist_covered;
ENTITY* vehicle;
function p_fade_beamy(PARTICLE* p)
{
p.alpha -= 3*time_step;
if(p.alpha <= 0) p.lifespan = 0;
}
function p_beamy(PARTICLE* p)
{
VECTOR speed;
vec_set(p.vel_x,dist_covered.x);
if(p.vel_x != 0 || p.vel_y != 0 || p.vel_z != 0) vec_randomize(p.vel_x,1);
p.alpha = 100;
p.bmap = smoke;
p.size = 8;
set(p, MOVE | TRANSLUCENT | BEAM );
p.event = p_fade_beamy;
}
action movable_vehicle()
{
VECTOR temp;
VECTOR vtemp1;
VECTOR vtemp2;
vehicle = my;
while(1)
{
vec_set(vtemp1.x,my.x);
c_move(my,vector((key_cuu-key_cud)*5*time_step,0,0),nullvector,GLIDE | IGNORE_PASSABLE);
my.pan -= (key_cur-key_cul)*5*time_step;
vec_set(vtemp2.x,my.x);
vec_diff(dist_covered,vtemp1.x,vtemp2.x);
vec_set(temp.x,vector(-37,0,0));
vec_rotate(temp.x,my.pan);
vec_add(temp.x,my.x);
effect(p_beamy,40,temp.x,nullvector);
wait(1);
}
}
You can download a testing sample here (open through "main.c"): http://www.datafilehost.com/d/38f7e3bdAlso, I wanted to ask: Does the particle function preserve my/you pointers from the calling function? I know in C-script the my pointer is used to point to the particle ,but what about Lite-C? Thank you for reading & any help would be appreciated  ....
Nothing to say ....
|
|
|
Re: Problem with my beam effect
[Re: CyberGhost]
#442793
07/03/14 06:28
07/03/14 06:28
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
You probably just needed to play more with some values  Here, grab this demo: Smoke TrailHere is the code itself:
// include lib:
#include <acknex.h>
#include <default.c>
// game paths:
#define PRAGMA_PATH "data"
// define test level's name:
STRING* levelStr = "";
// particle bmap:
BMAP* smoke_tga = "smoke.tga";
// helper function:
function vec_randomize(VECTOR* vec, var range){
vec_set(vec, vector(random(1) - 0.5, random(1) - 0.5, random(1) - 0.5));
vec_normalize(vec, random(range));
}
// fade particles:
function fadeSmoke(PARTICLE* p){
// decrease alpha:
p.alpha -= (2 + random(2)) * time_step;
// increase size:
p.size += (1 + random(2)) * time_step;
// if alpha is low enough, kill particle:
if(p.alpha < 0){ p.lifespan = 0; }
}
// simple smoke particle effect:
function smokeEffect(PARTICLE* p){
// vector for particle's movement:
VECTOR vTemp;
// randomize movement of smoke:
vec_randomize(vTemp, 1);
// add calculated movement to particle itself:
vec_add(p.vel_x, vTemp);
// define random size for smoke:
p.size = 1 + random(2);
// define random alpha for smoke:
p.alpha = 65 + random(10);
// define smoke bmap:
p.bmap = smoke_tga;
// define gravity for smoke:
p.gravity = 0.5; // play with this, or even remove
// setup some flags:
set(p, MOVE | BRIGHT | TRANSLUCENT);
// define fading event for smoke:
p.event = fadeSmoke;
}
// simple rocket going in circles:
action actRocket(){
// flags:
set(my, PASSABLE | BRIGHT | UNLIT);
// run this loop until we exist:
while(my){
// calulate new position each frame:
my.x = my.skill1 + fsin(total_ticks * 10, 200);
my.y = my.skill2 + fcos(total_ticks * 10, 200);
// spawn one smoke particle each frame from my position:
effect(smokeEffect, 1, my.x, nullvector);
// wait one frame:
wait(1);
}
}
// fog, sky color setup:
void fogSkySetup(){
// set camera positions/angles:
vec_set(camera.x, vector(-40, -444, 370));
vec_set(camera.pan, vector(85, -42, 0));
// lods:
vec_set(d3d_lodfactor, vector(12.5, 25, 50));
// sunlight:
sun_light = 100;
// camera clipping parameters:
camera.clip_near = 1;
camera.clip_far = 3000;
// fog parameters:
camera.fog_start = 250;
camera.fog_end = 2500;
// fog and sky colors:
fog_color = 4;
// change fog color:
vec_set(d3d_fogcolor4.blue, vector(120, 120, 120));
// change sky color:
vec_set(sky_color.blue, d3d_fogcolor4.blue);
}
// main game function:
void main(){
// disable v-sync:
d3d_triplebuffer = 1;
// turn doppler effect OFF:
doppler_factor = 0;
// preload in buffer all created models:
preload_mode = 3;
// show all errors:
warn_level = 6;
// set maximal framerate:
fps_max = 60;
// smooth time step:
time_smooth = 0.5;
// window title:
video_window(NULL, NULL, NULL, "Test");
// video modes:
video_set(800, 600, 16, 2);
video_set(0, 0, 16, 2);
// no wide-screen:
video_aspect = 1.333;
// freeze the game:
freeze_mode = 1;
// load the level:
level_load(levelStr);
// wait three frames:
wait(1);
// unfreeze the game:
freeze_mode = 0;
// adjust weather:
fogSkySetup();
// seed the random sequence:
random_seed(0);
// create a model:
ENTITY* testEnt = ent_create("bbox.mdl", nullvector, actRocket);
}
And a screen, to show you how does it looks like: Greets!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|