Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Bobboau on October 22, 2002, 02:44:10 am

Title: warp in model now loading from pof
Post by: Bobboau on October 22, 2002, 02:44:10 am
as you can see in the image below I have gotten the warphole model to render as it should in game, this will be most usefull for TBP, but it does offer an improvement for normal FS as well, I still have to implement LOD and as you can see in the image I forgot to turn off backface culling (fixed it right after takeing the pic), but this is one of the things that we have wanted for a while, and the code I used can be used for other such cool efects like 3D explosions and such
(http://freespace.volitionwatch.com/blackwater/newsubspace.jpg)
I will commit this as soon as I get it all ironed out
(I may save my changes and start from a clean update becase I have developed this problem were the game has a 40% chance of hard freazeing on stratup, it didn't start doing this untill after I commited my last changes so I'm worried that this may be something that was introduced around that time, by me or someone else)
Title: warp in model now loading from pof
Post by: Sesquipedalian on October 22, 2002, 08:05:18 am
Btw, how did it used to work?
Title: warp in model now loading from pof
Post by: aldo_14 on October 22, 2002, 08:06:20 am
Quote
Originally posted by Sesquipedalian
Btw, how did it used to work?


ani mapped onto a flat polygon, I think.

This allows, I reckon, for better subspace 'tunnels' to be modelled (as the warpout pof)
Title: warp in model now loading from pof
Post by: Fury on October 22, 2002, 08:48:54 am
Quote
Originally posted by aldo_14


ani mapped onto a flat polygon, I think.

This allows, I reckon, for better subspace 'tunnels' to be modelled (as the warpout pof)


You think we could have 3D jump point?

Most definitely a good think for TBP, B5 cone-like jump point.
There at least two different effects though... one seen in A Call to Arms-movie and another in the series and ItB. And a new one seen in The Legend of the Rangers.
Title: warp in model now loading from pof
Post by: Bobboau on October 22, 2002, 09:03:26 am
the way it's setup, you can have any model that falls within the normal pof limetations, and any warpin/out (these can still be diferent) ani mapped to it, I actualy made a warp model for TBP for testing though it could use some work,
is there a quick vidio of a ship exiting hyperspace that I could examine to try and reproduce for the effect
Title: warp in model now loading from pof
Post by: tomcat on October 22, 2002, 09:11:29 am
Bob that is the most USEFULL thing u did for TBP with source code;7  -- try it with a cone one but with a animated texture that make like it is changing alpha channel from 0% to final blue efect:)
Title: warp in model now loading from pof
Post by: Fury on October 22, 2002, 09:29:58 am
Five short avi captures are soon up. Wait a few mins.

OK, here are ITB captures. (http://koti.mbnet.fi/~fury/misc/itb.zip)

And Bobboau, don't you have ICQ? Communication would be tad easier. :)
Title: warp in model now loading from pof
Post by: Bobboau on October 22, 2002, 07:57:05 pm
no ICQ, it doesn't like me and the feeling is mutual

for the coders (and me for backup)

WarpInEffect.cpp
add
Code: [Select]

float model_Interp_scale_x; //added these three for warpin stuff-Bobbau
float model_Interp_scale_y;
float model_Interp_scale_z;
int marp_Model; //global warp model number


replace
Code: [Select]

void warpin_render(matrix *orient, vector *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius )
{

int i;

int saved_gr_zbuffering = gr_zbuffer_get();

// gr_zbuffering = 0;


float Grid_depth = radius/2.5f;

vector center;

vm_vec_scale_add( ¢er, pos, &orient->vec.fvec, -(max_radius/2.5f)/3.0f );

// Warp_Map = texture_bitmap_num;//sets the warp map, and thus sets the interp flag for this being a warpin effect
vector vecs[5];
vertex verts[5];

if(wm > -1){
model_Interp_scale_x = radius /20;
model_Interp_scale_y = radius /20;
model_Interp_scale_z = radius /20;

set_warp_gloabals(model_Interp_scale_x, model_Interp_scale_y, model_Interp_scale_z, texture_bitmap_num);

float dist = vm_vec_dist_quick( pos, &Eye_position );

model_set_detail_level((int)(dist / (radius * 10.0f)));
gr_set_cull(0);
model_render( wm, orient, pos, MR_NO_LIGHTING | MR_NORMAL);
gr_set_cull(1);

// Warp_Map = -1;//un sets the warp map

model_Interp_scale_x = 1.0f;
model_Interp_scale_y = 1.0f;
model_Interp_scale_z = 1.0f;

set_warp_gloabals(model_Interp_scale_x, model_Interp_scale_y, model_Interp_scale_z, -1);

vecs[4] = center; //this is for the warp glow-Bobboau
verts[4].u = 0.5f; verts[4].v = 0.5f;
g3_rotate_vertex( &verts[4], &vecs[4] );

}else{
gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );

vm_vec_scale_add( &vecs[0], ¢er, &orient->vec.uvec, radius );
vm_vec_scale_add2( &vecs[0], &orient->vec.rvec, -radius );
vm_vec_scale_add2( &vecs[0], &orient->vec.fvec, Grid_depth );

vm_vec_scale_add( &vecs[1], ¢er, &orient->vec.uvec, radius );
vm_vec_scale_add2( &vecs[1], &orient->vec.rvec, radius );
vm_vec_scale_add2( &vecs[1], &orient->vec.fvec, Grid_depth );

vm_vec_scale_add( &vecs[2], ¢er, &orient->vec.uvec, -radius );
vm_vec_scale_add2( &vecs[2], &orient->vec.rvec, radius );
vm_vec_scale_add2( &vecs[2], &orient->vec.fvec, Grid_depth );

vm_vec_scale_add( &vecs[3], ¢er, &orient->vec.uvec, -radius );
vm_vec_scale_add2( &vecs[3], &orient->vec.rvec, -radius );
vm_vec_scale_add2( &vecs[3], &orient->vec.fvec, Grid_depth );

// vm_vec_scale_add( &vecs[4], ¢er, &orient->vec.fvec, -Grid_depth );
vecs[4] = center;

verts[0].u = 0.01f; verts[0].v = 0.01f;
verts[1].u = 0.99f; verts[1].v = 0.01f;
verts[2].u = 0.99f; verts[2].v = 0.99f;
verts[3].u = 0.01f; verts[3].v = 0.99f;
verts[4].u = 0.5f; verts[4].v = 0.5f;

for (i=0; i<5; i++ ) {
g3_rotate_vertex( &verts[i], &vecs[i] );
}

draw_face( &verts[0], &verts[4], &verts[1] );
draw_face( &verts[1], &verts[4], &verts[2] );
draw_face( &verts[4], &verts[3], &verts[2] );
draw_face( &verts[0], &verts[3], &verts[4] );
}
if ( Warp_glow_bitmap != -1 ) {
gr_set_bitmap( Warp_glow_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );

float r = radius;

int render_it;

#define OUT_PERCENT1 0.80f
#define OUT_PERCENT2 0.90f

#define IN_PERCENT1 0.10f
#define IN_PERCENT2 0.20f

if ( life_percent < IN_PERCENT1 ) {
// do nothing
render_it = 0;
} else if ( life_percent < IN_PERCENT2 ) {
r *= ( life_percent-IN_PERCENT1 ) / (IN_PERCENT2-IN_PERCENT1);
render_it = 1;
} else if ( life_percent < OUT_PERCENT1 ) {
// do nothing
render_it = 1;
} else if ( life_percent < OUT_PERCENT2 ) {
r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2-OUT_PERCENT1);
render_it = 1;
} else {
// do nothing
render_it = 0;
}

if (render_it) {
int saved_gr_zbuffering = gr_zbuffer_get();
gr_zbuffer_set(GR_ZBUFF_READ);

// Add in noise
//float Noise[NOISE_NUM_FRAMES] = {
int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES;

r *= (0.40f + Noise[noise_frame]*0.30f);

g3_draw_bitmap( &verts[4], 0,r, TMAP_FLAG_TEXTURED );
gr_zbuffer_set(saved_gr_zbuffering);
}
}

gr_zbuffer_set( saved_gr_zbuffering );
}



in FireBalls.cpp
replace
Code: [Select]

void fireball_load_data()
{
int i, idx;
fireball_info *fd;

for ( i = 0; i < MAX_FIREBALL_TYPES; i++ ) {
fd = &Fireball_info[i];

for(idx=0; idxlod_count; idx++){
fd->lod[idx].bitmap_id = bm_load_animation( fd->lod[idx].filename, &fd->lod[idx].num_frames, &fd->lod[idx].fps, 1 );
if ( fd->lod[idx].bitmap_id < 0 ) {
Error(LOCATION, "Could not load %s anim file\n", fd->lod[idx].filename);
}
}
}

if ( Warp_glow_bitmap == -1 ) {
Warp_glow_bitmap = bm_load( NOX("warpglow01") );
}

polymodel Warp_pm;
mprintf(("loading warp model\n"));
wm = -1;
wm = model_load("warp.pof", 0, NULL);
}



add
Code: [Select]
extern int wm;to FireBalls.h,
origonaly I tried doing this with a buch of globals but it didn't workout right

in ModelInterp.cpp
this gets spliced into model_interp_defpoints between the part that scales the thrusters and the part that does everything else
Code: [Select]

} else if((Model_Interp_scale_x != 1) || (Model_Interp_scale_y != 1) || (Model_Interp_scale_z != 1)) {

mprintf(("warp model being scaled by %f %f %f\n",Model_Interp_scale_x ,Model_Interp_scale_y, Model_Interp_scale_z));
for (n=0; n {
vector tmp;

Interp_verts[n] = src;

tmp.xyz.x = src->xyz.x * Model_Interp_scale_x;
tmp.xyz.y = src->xyz.y * Model_Interp_scale_y;
tmp.xyz.z = src->xyz.z * Model_Interp_scale_z;

g3_rotate_vertex(dest,&tmp);

src++; // move to normal

for (i=0; i {
Interp_light_applied[next_norm] = 0;
Interp_norms[next_norm] = src;

next_norm++;
src++;
}
dest++;
}
}else{



replace model_interp_tmappoly (there'se stuff other than just the warp thing added to this)
Code: [Select]

void model_interp_tmappoly(ubyte * p,polymodel * pm)
{
vertex *Interp_list[TMAP_MAX_VERTS];
int i;
int nv;
model_tmap_vert *verts;

int is_invisible = 0;

if(Warp_Map < 0){
if ((!Interp_thrust_scale_subobj) && (pm->textures[w(p+40)]<0)) {
// Don't draw invisible polygons.
if ( !(Interp_flags & MR_SHOW_INVISIBLE_FACES)) {
return;
} else {
is_invisible = 1;
}
}
}


nv = w(p+36);

// Tmap_show_layers = 1;

#ifndef NDEBUG
modelstats_num_polys++;
#endif

if(Warp_Map < 0){
if (!g3_check_normal_facing(vp(p+20),vp(p+8)) && !(Interp_flags & MR_NO_CULL)) return;
}

if ( nv < 0 ) return;

verts = (model_tmap_vert *)(p+44);


for (i=0;i {
Interp_list[i] = &Interp_points[verts[i].vertnum];

Interp_list[i]->u = verts[i].u;
Interp_list[i]->v = verts[i].v;

if ( Interp_subspace ) {
Interp_list[i]->v += Interp_subspace_offset_u;
Interp_list[i]->u += Interp_subspace_offset_v;
Interp_list[i]->r = Interp_subspace_r;
Interp_list[i]->g = Interp_subspace_g;
Interp_list[i]->b = Interp_subspace_b;
} else {

// if ( !(pm->flags & PM_FLAG_ALLOW_TILING) ) {
// Assert(verts[i].u <= 1.0f );
// Assert(verts[i].v <= 1.0f );
// }

// Assert( verts[i].normnum == verts[i].vertnum );

if ( (Interp_flags & MR_NO_LIGHTING) || (pm->ambient[w(p+40)])) { //gets the ambient glow to work
if ( D3D_enabled ) {
Interp_list[i]->r = 191;
Interp_list[i]->g = 191;
Interp_list[i]->b = 191;
} else {
Interp_list[i]->b = 191;
}
} else {
int vertnum = verts[i].vertnum;
int norm = verts[i].normnum;

if ( Interp_flags & MR_NO_SMOOTHING ) {
if ( D3D_enabled ) {
light_apply_rgb( &Interp_list[i]->r, &Interp_list[i]->g, &Interp_list[i]->b, Interp_verts[vertnum], vp(p+8), Interp_light );
} else {
Interp_list[i]->b = light_apply( Interp_verts[vertnum], vp(p+8), Interp_light );
}
} else {
// if we're applying lighting as normal, and not using saved lighting
if ( !Interp_use_saved_lighting && !Interp_light_applied[norm] ) {

if ( D3D_enabled ) {
light_apply_rgb( &Interp_lighting->r[norm], &Interp_lighting->g[norm], &Interp_lighting->b[norm], Interp_verts[vertnum], Interp_norms[norm], Interp_light );

} else {
int li;
ubyte l;
l = light_apply( Interp_verts[vertnum], Interp_norms[norm], Interp_light );


if ( Detail.lighting > 1 ) {
// Add in precalculated muzzle flashes
float fl = i2fl(l)/255.0f;
ubyte *tmp = &Interp_lights[norm*pm->num_lights];

for ( li=0; linum_lights; li++ ) {
fl += i2fl(tmp[li])*pm->lights[li].value;
}

if ( fl < 0.0f ) {
fl = 0.0f;
} else if ( fl > 1.0f ) {
fl = 1.0f;
}

l = (ubyte)fl2i(fl*255.0f);

}

Interp_lighting->b[norm] = l;
}


Interp_light_applied[norm] = 1;
}

if ( D3D_enabled ) {
Interp_list[i]->r = Interp_lighting->r[norm];
Interp_list[i]->g = Interp_lighting->g[norm];
Interp_list[i]->b = Interp_lighting->b[norm];
} else {
Interp_list[i]->b = Interp_lighting->b[norm];
}
}
}
}

// Assert(verts[i].u >= 0.0f );
// Assert(verts[i].v >= 0.0f );
}

#ifndef NDEBUG
modelstats_num_polys_drawn++;
#endif


if (!(Interp_flags & MR_NO_POLYS) ) {
if ( is_invisible ) {
gr_set_color( 0, 255, 0 );
g3_draw_poly( nv, Interp_list, 0 );
} else if (Interp_thrust_scale_subobj) {
if ((Interp_thrust_bitmap>-1) && (Interp_thrust_scale > 0.0f) && !Pofview_running) {
gr_set_bitmap( Interp_thrust_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.2f );
g3_draw_poly( nv, Interp_list, TMAP_FLAG_TEXTURED );
} else if(!Pofview_running){
if ( !(Interp_flags & MR_SHOW_OUTLINE_PRESET) ) {
gr_set_color( 128, 128, 255 );
}
uint tflags = Interp_tmap_flags;
tflags &= (~(TMAP_FLAG_TEXTURED|TMAP_FLAG_TILED|TMAP_FLAG_CORRECT));
g3_draw_poly( nv, Interp_list, tflags );
}
} else if(Warp_Map > -1){ //warpin effect-Bobboau
gr_set_bitmap( Warp_Map, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
g3_draw_poly( nv, Interp_list, TMAP_FLAG_TEXTURED );
}else{
// all textured polys go through here
if ( Interp_tmap_flags & TMAP_FLAG_TEXTURED ) {
// subspace special case
if ( Interp_subspace && D3D_enabled ) {
gr_set_bitmap( pm->textures[w(p+40)], GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.2f );
}
// all other textures
else {
int texture;

// if we're rendering a nebula background pof, maybe select a custom texture
if((Interp_flags & MR_FORCE_TEXTURE) && (Interp_forced_bitmap >= 0)){
texture = Interp_forced_bitmap;
} else {
if (pm->is_ani[w(p+40)]){
texture = pm->textures[w(p+40)] + ((timestamp() / (int)(pm->fps[w(p+40)])) % pm->numframes[w(p+40)]);//here is were it picks the texture to render for ani-Bobboau
}else{
texture = pm->textures[w(p+40)];//here is were it picks the texture to render for normal-Bobboau
}
}

// muzzle flashes draw xparent
if(Interp_flags & MR_ALL_XPARENT){
gr_set_bitmap( texture, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, Interp_xparent_alpha );
} else {
if(pm->transparent[w(p+40)]){ //trying to get transperent textures-Bobboau
gr_set_bitmap( texture, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 0.8f );
}else{
gr_set_bitmap( texture );
}
}
}
} else {
if ( !(Interp_flags & MR_SHOW_OUTLINE_PRESET) ) {
gr_set_color( 128, 128, 128 );
}
}

if ( Interp_subspace ) {
g3_draw_poly( nv, Interp_list, TMAP_FLAG_TEXTURED|TMAP_FLAG_TILED|TMAP_FLAG_CORRECT );
} else {
if(Interp_flags & MR_ALL_XPARENT){
g3_draw_poly( nv, Interp_list, Interp_tmap_flags );
} else {
g3_draw_poly( nv, Interp_list, Interp_tmap_flags|TMAP_FLAG_NONDARKENING );
}
}
}
}

if (Interp_flags & (MR_SHOW_OUTLINE|MR_SHOW_OUTLINE_PRESET) ) {

if ( Interp_flags & MR_SHOW_OUTLINE ) {
gr_set_color_fast( &Interp_outline_color );
}

for (i=0; i {
int j = (i + 1) % nv;
g3_draw_line(Interp_list[i], Interp_list[j] );
}
}

}


some gloabals for the model system
Code: [Select]

float Model_Interp_scale_x = 1.0f; //added these three for warpin stuff-Bobbau
float Model_Interp_scale_y = 1.0f;
float Model_Interp_scale_z = 1.0f;
int Warp_Model = -1; //global warp model number
int Warp_Map = -1; //global map to be used while rendering the warp model


this sets the globals from the warpin effect
Code: [Select]

void set_warp_gloabals(float, float, float, int);

void set_warp_gloabals(float a, float b, float c, int d){
Model_Interp_scale_x =a;
Model_Interp_scale_y=b;
Model_Interp_scale_z=c;
Warp_Map=d;
mprintf(("warpmap being set to %d\n",Warp_Map));
}
Title: warp in model now loading from pof
Post by: Joey_21 on October 22, 2002, 08:14:15 pm
Very neat. :nod:
Title: warp in model now loading from pof
Post by: Bobboau on October 22, 2002, 10:41:50 pm
looking at those clips I may have to add a step in frot of the current warpin effect were it has a cone of beam like objects and the warp glow that fade just as the warp model opens,
might it be a good idea to scale the ship models as they are going through the effect (I think I can do that now)
Title: warp in model now loading from pof
Post by: LAM3O on October 23, 2002, 12:18:28 am
"might it be a good idea to scale the ship models as they are going through the effect (I think I can do that now)
"

Amazing!!!
Title: warp in model now loading from pof
Post by: Bobboau on October 23, 2002, 12:56:45 am
key word being 'think', I haven't actualy tried yet
Title: warp in model now loading from pof
Post by: Fury on October 23, 2002, 04:23:04 am
Quote
Originally posted by Bobboau
might it be a good idea to scale the ship models as they are going through the effect (I think I can do that now)


Wow... until now I thought that is not possible...
Way to go Bobboau! I hope you will succeed! :D
Title: warp in model now loading from pof
Post by: DTP on October 23, 2002, 04:06:45 pm
maybe you could even make it so, that you can´t see ships from behind the warphole.

right, now.

you just see a ship appearing, and in case of scale, you would see a ship "grow".

and in the case it has to travel a bit while it grows like in TBP

Disable collisions or else u know what will happen to ships behind the warphole.
Title: warp in model now loading from pof
Post by: Bobboau on October 23, 2002, 11:50:26 pm
ships in stage 1 warpin already have there colision disabled
Title: warp in model now loading from pof
Post by: RandomTiger on October 24, 2002, 10:22:14 am
Quote
Originally posted by DTP
maybe you could even make it so, that you can´t see ships from behind the warphole.


You could use the dot product of the direction of the cone and the vector from the cone start to the viewing ship to determine if it should be seen by checking the resulting angle against the average angle of the cone.

(http://www.ijbrooks.demon.co.uk/tom/dot.gif)
Title: warp in model now loading from pof
Post by: Fury on October 27, 2002, 02:58:44 am
By the way, would it be possible somehow define jump anim size regardless of ship's size?

I mean, mostly only military ships have jump capability in B5. It would add a lot of atmosphere to our mod if we could simulate this in the way that one jump point is used by numerous ships.
Title: warp in model now loading from pof
Post by: RandomTiger on October 27, 2002, 01:31:12 pm
Quote
Originally posted by Mr. Fury
By the way, would it be possible somehow define jump anim size regardless of ship's size?

I mean, mostly only military ships have jump capability in B5. It would add a lot of atmosphere to our mod if we could simulate this in the way that one jump point is used by numerous ships.


That would be very cool for TBP and other mods.
Title: warp in model now loading from pof
Post by: Anaz on October 27, 2002, 03:42:59 pm
I think I know how to do that just using this...
you make a big invisible cube, and have it warp in, and in the space where it warps in, you just have all of the ships that you want to appear come out with no warp effect.
Title: warp in model now loading from pof
Post by: Solatar on October 27, 2002, 03:46:49 pm
Yeah, but make sure the cube has a "no_collide_invisible" tag. Or it might look funny.
Title: warp in model now loading from pof
Post by: IceFire on October 27, 2002, 03:48:31 pm
It'd be nicer if something like that happened autmatically... :)
Title: warp in model now loading from pof
Post by: DTP on October 27, 2002, 07:49:33 pm
Quote
Originally posted by Mr. Fury
By the way, would it be possible somehow define jump anim size regardless of ship's size?

I mean, mostly only military ships have jump capability in B5. It would add a lot of atmosphere to our mod if we could simulate this in the way that one jump point is used by numerous ships.


a perhaps more usefull way would be to have to the effect appearing at an user set spot at a user set size, sort like actually having jumpoints forming on events.

so you could set some "jump points" sort like jump nodes, but where these actually has an effect that can be activated by an event sort like this

sexp

when distance <100
-form jump point
-ship(to get an angle)
-duration in ms
-size


if the ships would be warping out would be up to the mission designer, so he could make a simulated faulted jump attempt.
Title: warp in model now loading from pof
Post by: Galemp on October 27, 2002, 08:22:46 pm
Quote
Originally posted by DTP

if the ships would be warping out would be up to the mission designer, so he could make a simulated faulted jump attempt.


Or node collapses? ;7
Title: warp in model now loading from pof
Post by: Fury on October 28, 2002, 04:41:20 am
Hmh, how about we can define that multiple ships are actually using a single jump point? Let it be like "Wings", you form a group of ships that uses same jump. Naturally this disables ship specific jump for selected ships. Much like it does when forming wings.

In "jump group" editor you can also define if a group arrives through a single jump point or if it is leaving through a single jump point. If the group arrives, it disabled arriving warp in area in ship status window and if group leaves it disabled warp out area in ship status window.

Also, I hope this would support friendly, hostile, unknown and neutral ships in same jump group.

All you need is to place ships in fred2, make them as "jump group" and they will appear in-game in their respective places. Jump point is as large as is necessary, so it is also important not to make groups where ships are 10km away each other. ;) That would make an impressive jump anim. :D


Example:
Friendly ships A and B arrives to fight off enemies through same jump point.

Hostiles are running and Friendly B is chasing Hostile A, Hostile A jumps and Friendly B jumps after through SAME jump point.

Edit: Propbably not the best idea... :rolleyes: