1 registered members (AndrewAMD),
1,248
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: xXxGuitar511]
#120831
07/11/07 21:19
07/11/07 21:19
|
Joined: Oct 2005
Posts: 528 Italy
Mondivirtuali
User
|
User
Joined: Oct 2005
Posts: 528
Italy
|
HI, me again I dl the trial of mudbox and I done a pair or test np, also I did some NP using 3dbrush, for compare both the software. The maps seems to be right: but , using both the softwares ,the final risults is not that right: Where in the highpoly models there are bumpies, the normal mapped models do shows indentations. Many details ,done with Mudbox ,are missed also. The shader seems to be works, there are some mistake in the detailing process.
Last edited by Mondivirtuali; 07/11/07 21:23.
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: Mondivirtuali]
#120832
07/12/07 05:38
07/12/07 05:38
|
Joined: May 2002
Posts: 2,541 Berlin
EX Citer
Expert
|
Expert
Joined: May 2002
Posts: 2,541
Berlin
|
Thanks for the shader, xXxGuitar511! And thanks for hosting, Spike!
:L
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: xXxGuitar511]
#120833
07/16/07 03:18
07/16/07 03:18
|
Joined: Apr 2006
Posts: 1,551 Netherlands
D3D
Serious User
|
Serious User
Joined: Apr 2006
Posts: 1,551
Netherlands
|
Tried it with Lite-c and it worked very nice with the Doompack NormalMapCode:
//-------------------------------------------------------------- // Normal Mapping Shader // // Matt_Aufderheide, Bloodline, William, xXxGuitar511 // ------------------------------------------------------------- // title: Normal Mapping Shader // text: - // -------------------------------------------------------------
#include <acknex.h> #include <default.c>
// entry: FX File: STRING* fxNM = "NM.fx"; STRING* MyAppTitle = "Normal Mapping Shader";
// section: Ambient Lighting: // enable: Faked Dynamics #define staFake // enable: Ambience #define staAmb
MATERIAL* comics = { ambient_blue = 100; ambient_green = 100; ambient_red = 100; albedo = 0; }
MATERIAL* mat_NM = { // section: Diffuse: // entry: Red diffuse_red = 255; // entry: Green diffuse_green = 255; // entry: Blue diffuse_blue = 255; // section: Ambient: // entry: Red ambient_red = 16.0; // entry: Green ambient_green = 16.0; // entry: Blue ambient_blue = 16.0; // // section: Sun: // // entry: Red // specular_red = 64.0; // // entry: Green // specular_green = 64.0; // // entry: Blue // specular_blue = 64.0; // section: Static Lighting: // entry: Red emissive_red = 255.0; // entry: Green emissive_green = 255.0; // entry: Blue emissive_blue = 255.0; // flags = tangent | enable_render; effect = fxNM; //event = checkLight; }
function effect_startup() { effect_load(mat_NM, fxNM); // var SLF; while(1) { SLF = 0; #ifdef staAmb SLF += 1; #endif #ifdef staFake SLF += 2; #endif // vec_set(mat_NM.specular_blue, sun_color); mat_NM.skill1 = pixel_for_vec(nullvector, SLF*10, 8888); wait(1); } }
//function checkLight() //{ // vec_set(temp, my.x); // temp.z -= floor_range; // c_trace(my.x, temp, ignore_me | scan_texture); // mtl.skill1 = pixel_for_vec(tex_color, tex_light, 8888); //}
#define _Red skill1 #define _Green skill2 #define _Blue skill3 #define _Range skill4 // action: Dynamic Light // text: - // skill1: Red 128 // skill2: Green 128 // skill3: Blue 128 // skill4: Range 300 action DLight() { my.red = my._Red; my.green = my._Green; my.blue = my._Blue; my.lightrange = my._Range; set(my,LIGHT); }
void init_normal() { effect_startup(); }
action SpinMe() { while(1) { my.material = mat_NM; my.pan -= 2 * time_smooth; wait(1); } }
void main() { fps_max = 60; video_mode = 6; video_window(vector(375,350,0),NULL,112,MyAppTitle); screen_color.blue = 125; level_load("normal.wmb"); wait(2); init_normal(); }
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: D3D]
#120834
07/16/07 18:59
07/16/07 18:59
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
EXCiter: Actually I've gotten some webspace from AienHeretic...
D3D: Thanks for testing it bro! Glad it will be usefull in A7 (if it's still needed), and that our users now know how to use it with Lite-C
xXxGuitar511 - Programmer
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: xXxGuitar511]
#120835
07/17/07 04:38
07/17/07 04:38
|
Joined: Aug 2004
Posts: 137
foodstamp
Member
|
Member
Joined: Aug 2004
Posts: 137
|
ok i have included the litc version in my main.c file of the car test level but it is not showung NM as a mat file when I do the properties. did i do something worong ? Code:
////////////////////////////////////////////////////////////// // carlevel main.c: Load level,init physics, do camera control ////////////////////////////////////////////////////////////// #include <acknex.h> #include <default.c>
var camera_arc=100; //////////////////////////////////////////////////////////////
function start_all(); function zoom_cam();
// global vars FONT* fontArial = "Arial#20b"; // truetype font ENTITY* pFocus; // camera will orbit around this entity var temp[3]; var temp2[3];
////////////////////////////////////////////////////////////// #include "NM.c" #include "physics_car.c" // <--- that's where the magic happens #include "startup01.c" // splash screen #include "cg_add.c" // Czeslaw Gorski actions //////////////////////////////////////////////////////////////
Last edited by foodstamp; 07/17/07 04:47.
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: foodstamp]
#120836
07/17/07 05:02
07/17/07 05:02
|
Joined: Apr 2006
Posts: 1,551 Netherlands
D3D
Serious User
|
Serious User
Joined: Apr 2006
Posts: 1,551
Netherlands
|
The mat_NM is already assigned when you attached the action SpinMe to the entity of your choice. You can also attach the DLight action to a dummy model if you like. Try: Code:
////////////////////////////////////////////////////////////// // carlevel main.c: Load level,init physics, do camera control ////////////////////////////////////////////////////////////// #include <acknex.h> #include <default.c> #include "physics_car.c" // <--- that's where the magic happens #include "startup01.c" // splash screen #include "cg_add.c" // Czeslaw Gorski actions #include "NM.c" //////////////////////////////////////////////////////////////
var camera_arc=100; //////////////////////////////////////////////////////////////
function start_all(); function zoom_cam();
// global vars FONT* fontArial = "Arial#20b"; // truetype font ENTITY* pFocus; // camera will orbit around this entity var temp[3]; var temp2[3];
Note: copy/paste the relevant code from NM.c to main.c, or clean the NM.c script before including it to the mainscript of the carlevel demo.
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: D3D]
#120837
07/17/07 14:12
07/17/07 14:12
|
Joined: Aug 2004
Posts: 137
foodstamp
Member
|
Member
Joined: Aug 2004
Posts: 137
|
OK so would i include the NM.c file into physics_car.c or would i need to copy certain parts of NM.c into the physics_car.c file i hate when the only programmer goes on vacation. Not that I cant learn anything. But it takes a bit for me to catch on to stuff
Last edited by foodstamp; 07/17/07 14:27.
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: foodstamp]
#120838
07/17/07 14:30
07/17/07 14:30
|
Joined: Apr 2006
Posts: 1,551 Netherlands
D3D
Serious User
|
Serious User
Joined: Apr 2006
Posts: 1,551
Netherlands
|
Try make backup of carlevel directory and replace all code in main.c with: Code:
////////////////////////////////////////////////////////////// // carlevel main.c: Load level,init physics, do camera control ////////////////////////////////////////////////////////////// //-------------------------------------------------------------- // Normal Mapping Shader // // Matt_Aufderheide, Bloodline, William, xXxGuitar511 // ------------------------------------------------------------- // title: Normal Mapping Shader // text - // -------------------------------------------------------------
#include <acknex.h> #include <default.c>
var camera_arc=100; //////////////////////////////////////////////////////////////
function start_all(); function zoom_cam();
// global vars FONT* fontArial = "Arial#20b"; // truetype font ENTITY* pFocus; // camera will orbit around this entity var temp[3]; var temp2[3];
////////////////////////////////////////////////////////////// #include "physics_car.c" // <--- that's where the magic happens #include "startup01.c" // splash screen #include "cg_add.c" // Czeslaw Gorski actions //////////////////////////////////////////////////////////////
// NM SHADER CODE // section: Ambient Lighting: // enable: Faked Dynamics #define staFake // enable: Ambience #define staAmb
// entry: FX File: STRING* fxNM = "NM.fx"; // NM SHADER CODE
STRING* levelname = "loop.wmb"; ENTITY* sky = { type = "skycube+6.tga"; flags2 = SKY | CUBE | VISIBLE; }
////////////////////////////////////////////////////////////// // camera control (orbit around pFocus, or chase camera or cockpit cam
var camMode=-1; // 0:orbit, 1:chase, 2:cockpit, -1 disabled var rotspd=20; // cam movement speed var minang=5; var maxang=70; // orbit between 5-70 degrees and 300-3000 distance var mindist=200; var maxdist=3000;
var cameraTPos[3]; // camera target position var cameraTAng[3]; // camera target angle
#define KEY_CAMERA key_c // use this key to switch camera modes #define JOY_CAMERA joy_3
// NM SHADER CODE MATERIAL* comics = { ambient_blue = 100; ambient_green = 100; ambient_red = 100; albedo = 0; }
MATERIAL* mat_NM = { // section: Diffuse: // entry: Red diffuse_red = 255; // entry: Green diffuse_green = 255; // entry: Blue diffuse_blue = 255; // section: Ambient: // entry: Red ambient_red = 16.0; // entry: Green ambient_green = 16.0; // entry: Blue ambient_blue = 16.0; // // section: Sun: // // entry: Red // specular_red = 64.0; // // entry: Green // specular_green = 64.0; // // entry: Blue // specular_blue = 64.0; // section: Static Lighting: // entry: Red emissive_red = 255.0; // entry: Green emissive_green = 255.0; // entry: Blue emissive_blue = 255.0; // flags = tangent | enable_render; effect = fxNM; //event = checkLight; }
function effect_startup() { effect_load(mat_NM, fxNM); // var SLF; while(1) { SLF = 0; #ifdef staAmb SLF += 1; #endif #ifdef staFake SLF += 2; #endif // vec_set(mat_NM.specular_blue, sun_color); mat_NM.skill1 = pixel_for_vec(nullvector, SLF*10, 8888); wait(1); } }
//function checkLight() //{ // vec_set(temp, my.x); // temp.z -= floor_range; // c_trace(my.x, temp, ignore_me | scan_texture); // mtl.skill1 = pixel_for_vec(tex_color, tex_light, 8888); //}
#define _Red skill1 #define _Green skill2 #define _Blue skill3 #define _Range skill4 // action: Dynamic Light // text: - // skill1: Red 128 // skill2: Green 128 // skill3: Blue 128 // skill4: Range 300 action DLight() { my.red = my._Red; my.green = my._Green; my.blue = my._Blue; my.lightrange = my._Range; set(my,LIGHT); }
void init_normal() { effect_startup(); }
action SpinMe() { while(1) { my.material = mat_NM; my.pan -= 2 * time_smooth; wait(1); } } // NM SHADER CODE
////////////////////////////////////////////////////////////// function ControlCamera_startup() { // set fog and view params fog_color = 1; camera.fog_start=1000; camera.fog_end =1.2*camera.clip_far; camera.clip_near=25;
// init level and wait for focus object (we will orbit around it) while(pFocus==NULL || camMode<0){wait(1);}
// current distance from focus and ang var cam_dist=200; ANGLE cam_ang; // reset if previously rolled around cam_ang.pan= pFocus.pan-180; cam_ang.tilt=30; cam_ang.roll=0; while(1) { // for focus object (we will orbit around it) while(pFocus==NULL){wait(1);}
if (camMode==0) // free orbit cam { reset(pFocus,INVISIBLE); //orbit if(mouse_right) { cam_ang.pan+=rotspd*mouse_force.x; cam_ang.tilt+=rotspd*mouse_force.y; cam_ang.tilt=clamp(cam_ang.tilt,minang,maxang); }
// zoom with mousewheel cam_dist-=integer(mickey.z); cam_dist=clamp(cam_dist,mindist,maxdist);
// do some trig to find camera location and then aim it at pFocus camera.x=pFocus.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt)); camera.y=pFocus.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt)); camera.z=pFocus.z+sin(cam_ang.tilt)*cam_dist; vec_set(temp,pFocus.x); vec_sub(temp,camera.x); vec_to_angle(camera.pan,temp); } if (camMode==1) // chase cam { reset(pFocus,INVISIBLE); if(mouse_right) { // mouse moves head vecChaseAngOff.pan-=rotspd*mouse_force.x * time_step; vecChaseAngOff.tilt+=rotspd*mouse_force.y * time_step; vecChaseAngOff.pan=clamp(vecChaseAngOff.pan,-20,20); vecChaseAngOff.tilt=clamp(vecChaseAngOff.tilt,-20,20); } else { // return to center if(vecChaseAngOff.pan > 0.25) { vecChaseAngOff.pan -= 2* time_step; } if(vecChaseAngOff.pan < -0.25) { vecChaseAngOff.pan += 2* time_step; } if(vecChaseAngOff.tilt > 6) { vecChaseAngOff.tilt -= 2* time_step; } if(vecChaseAngOff.tilt < 5) { vecChaseAngOff.tilt += 2* time_step; }
}
vec_set(cameraTPos, vecChaseOffset); // move behind and up var offset; offset= clamp(0.01*linSpeed*linSpeed, -100,100); cameraTPos[0] -= offset; // offset by speed vec_rotate(cameraTPos, vector(ang(pFocus.pan),0,0)); vec_add(cameraTPos, pFocus.x);
// collide with any object in the way c_trace(pFocus.x,cameraTPos, (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS)); if(trace_hit == 1) { // offset from that target along the vector vec_set(cameraTPos,target); // offset from the wall along normal by the near clipping dist vec_normalize(normal,(camera.clip_near/2)); vec_add(cameraTPos,normal); // draw_text("HIT_BACK",30,300,vector(123,123,200)); } else { // make sure we don't 'clip' into walls next to us.. vec_diff(temp,pFocus.x,cameraTPos); vec_normalize(temp,camera.clip_near); vec_rotate(temp,vector(90,0,0)); vec_set(temp2,cameraTPos); vec_add(temp2,temp); // move out by the clip_near value c_trace(cameraTPos,temp2,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS)); if(trace_hit == 1) { // offset from that target along the vector vec_set(cameraTPos,target); // offset from the wall along normal by the near clipping dist vec_normalize(normal,(camera.clip_near/2)); vec_add(cameraTPos,normal); // draw_text("HIT_1",30,300,vector(123,123,200)); } else { // rotate temp back the other dir twice as much.. vec_rotate(temp,vector(-180,0,0)); vec_set(temp2,cameraTPos); vec_add(temp2,temp); // move out by the clip_near value c_trace(cameraTPos,temp2,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS)); if(trace_hit == 1) { // offset from that target along the vector vec_set(cameraTPos,target); // offset from the wall along normal by the near clipping dist vec_normalize(normal,(camera.clip_near/2)); vec_add(cameraTPos,normal); // draw_text("HIT_2",30,300,vector(123,123,200)); } }
}
// Smooth out transition... vec_diff(temp,cameraTPos,camera.x); var vscale = clamp((time_step*0.5),0.001,1); vec_scale(temp,vscale); vec_add(camera.x,temp);
// calc angle from camera to target... vec_diff(temp,pFocus.x,cameraTPos); vec_to_angle(cameraTAng,temp); // camera target angle looks at focus center vec_add(cameraTAng, vecChaseAngOff.pan); // tweak it // Smooth out rotation... vec_diff(temp,cameraTAng,camera.pan); temp[0] = ang(temp[0]); // note! only pan is needed in this game! vec_scale(temp,vscale); vec_add(camera.pan,temp); // vec_set(camera.pan,cameraTAng.pan); }
if (camMode==2) // cockpit view { //set(pFocus,INVISIBLE); // You might want to set this to on if using dashboard bitmap vec_set(camera.pan, pFocus.pan); vec_set(camera.x, pFocus.x); // raise seat and move to driver side vec_set(temp, vecDriverOffset); vec_rotate(temp, pFocus.pan); vec_add(camera.x, temp); } //toggle camera if (KEY_CAMERA || JOY_CAMERA) { while (KEY_CAMERA || JOY_CAMERA) { wait(1); } camMode+=1; if (camMode>2) { camMode=0; } // reset if previously rolled around vec_set(camera.pan, cam_ang); } wait(1); } }
////////////////////////////////////////////////////////////// // assign this to terrain for multitexturing, uses 2nd skin as detail map action ffp_terr_detail() { detail_size = 16; }
////////////////////////////////////////////////////////////// // assign this to MDLs when user is to drive on them action MakePoly() { set(my,POLYGON); }
var StopWatchOn;
function Stopwatch_startup() { while (1) { if (StopWatchOn) timerSeconds+= time_step/16; speed_and_time(); //cg wait(1); } }
function ToggleStopwatch() { StopWatchOn = !StopWatchOn; }
////////////////////////////////////////////////////////////// // main function main() { video_mode=7; //800x600 shadow_stencil= ON; d3d_autotransparency = ON; vec_set(d3d_lodfactor,vector(35,60,75)); // default LOD switches
on_t = ToggleStopwatch; on_f1 = help_me; on_h = EventImpact; on_i = EventHorn;
cg_start(); init_normal(); // NM SHADER wait(1); level_load(levelname); // show title screen and spin camera
while(pFocus==NULL){wait(1);}
// activate real camera camMode = 1; set(physics_panel,VISIBLE); }
action Prop() { phent_settype(my, PH_RIGID, PH_BOX); phent_setdamping(my, 10, 30); }
Now reload the cardemo level inside WED and attach the action SpinMe to the entity of choice. You can also add the dlight.mdl to the level and if i'm right the action Dlight will be attached by magic. Rebuild the level and run. Note: NM.fx,dlight.mdl must be in the carlevel directory.
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: D3D]
#120839
07/17/07 15:01
07/17/07 15:01
|
Joined: Aug 2004
Posts: 137
foodstamp
Member
|
Member
Joined: Aug 2004
Posts: 137
|
OK i am not the best explaining stuff. what i am attempting to do is use the shader on a car. So it allready has the carinit actiono selected. And of course it wont run without the carinit action being assigned Thank You
|
|
|
Re: Normal-Mapping Shader (The Best @ vsps2.0)
[Re: foodstamp]
#120840
07/17/07 15:12
07/17/07 15:12
|
Joined: Apr 2006
Posts: 1,551 Netherlands
D3D
Serious User
|
Serious User
Joined: Apr 2006
Posts: 1,551
Netherlands
|
Tried to add the nm.c code to psysics_car.c and put init_normal(); in the main function of main.c, but that did not really worked, guess because the buggy has no normal map. So you must create one first and add it before apply the normal mapping shader onto the model. main.cCode:
////////////////////////////////////////////////////////////// // carlevel main.c: Load level,init physics, do camera control ////////////////////////////////////////////////////////////// #include <acknex.h> #include <default.c>
var camera_arc=100; //////////////////////////////////////////////////////////////
function start_all(); function zoom_cam();
// global vars FONT* fontArial = "Arial#20b"; // truetype font ENTITY* pFocus; // camera will orbit around this entity var temp[3]; var temp2[3];
////////////////////////////////////////////////////////////// #include "physics_car.c" // <--- that's where the magic happens #include "startup01.c" // splash screen #include "cg_add.c" // Czeslaw Gorski actions //////////////////////////////////////////////////////////////
STRING* levelname = "loop.wmb"; ENTITY* sky = { type = "skycube+6.tga"; flags2 = SKY | CUBE | VISIBLE; }
////////////////////////////////////////////////////////////// // camera control (orbit around pFocus, or chase camera or cockpit cam
var camMode=-1; // 0:orbit, 1:chase, 2:cockpit, -1 disabled var rotspd=20; // cam movement speed var minang=5; var maxang=70; // orbit between 5-70 degrees and 300-3000 distance var mindist=200; var maxdist=3000;
var cameraTPos[3]; // camera target position var cameraTAng[3]; // camera target angle
#define KEY_CAMERA key_c // use this key to switch camera modes #define JOY_CAMERA joy_3
////////////////////////////////////////////////////////////// function ControlCamera_startup() { // set fog and view params fog_color = 1; camera.fog_start=1000; camera.fog_end =1.2*camera.clip_far; camera.clip_near=25;
// init level and wait for focus object (we will orbit around it) while(pFocus==NULL || camMode<0){wait(1);}
// current distance from focus and ang var cam_dist=200; ANGLE cam_ang; // reset if previously rolled around cam_ang.pan= pFocus.pan-180; cam_ang.tilt=30; cam_ang.roll=0; while(1) { // for focus object (we will orbit around it) while(pFocus==NULL){wait(1);}
if (camMode==0) // free orbit cam { reset(pFocus,INVISIBLE); //orbit if(mouse_right) { cam_ang.pan+=rotspd*mouse_force.x; cam_ang.tilt+=rotspd*mouse_force.y; cam_ang.tilt=clamp(cam_ang.tilt,minang,maxang); }
// zoom with mousewheel cam_dist-=integer(mickey.z); cam_dist=clamp(cam_dist,mindist,maxdist);
// do some trig to find camera location and then aim it at pFocus camera.x=pFocus.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt)); camera.y=pFocus.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt)); camera.z=pFocus.z+sin(cam_ang.tilt)*cam_dist; vec_set(temp,pFocus.x); vec_sub(temp,camera.x); vec_to_angle(camera.pan,temp); } if (camMode==1) // chase cam { reset(pFocus,INVISIBLE); if(mouse_right) { // mouse moves head vecChaseAngOff.pan-=rotspd*mouse_force.x * time_step; vecChaseAngOff.tilt+=rotspd*mouse_force.y * time_step; vecChaseAngOff.pan=clamp(vecChaseAngOff.pan,-20,20); vecChaseAngOff.tilt=clamp(vecChaseAngOff.tilt,-20,20); } else { // return to center if(vecChaseAngOff.pan > 0.25) { vecChaseAngOff.pan -= 2* time_step; } if(vecChaseAngOff.pan < -0.25) { vecChaseAngOff.pan += 2* time_step; } if(vecChaseAngOff.tilt > 6) { vecChaseAngOff.tilt -= 2* time_step; } if(vecChaseAngOff.tilt < 5) { vecChaseAngOff.tilt += 2* time_step; }
}
vec_set(cameraTPos, vecChaseOffset); // move behind and up var offset; offset= clamp(0.01*linSpeed*linSpeed, -100,100); cameraTPos[0] -= offset; // offset by speed vec_rotate(cameraTPos, vector(ang(pFocus.pan),0,0)); vec_add(cameraTPos, pFocus.x);
// collide with any object in the way c_trace(pFocus.x,cameraTPos, (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS)); if(trace_hit == 1) { // offset from that target along the vector vec_set(cameraTPos,target); // offset from the wall along normal by the near clipping dist vec_normalize(normal,(camera.clip_near/2)); vec_add(cameraTPos,normal); // draw_text("HIT_BACK",30,300,vector(123,123,200)); } else { // make sure we don't 'clip' into walls next to us.. vec_diff(temp,pFocus.x,cameraTPos); vec_normalize(temp,camera.clip_near); vec_rotate(temp,vector(90,0,0)); vec_set(temp2,cameraTPos); vec_add(temp2,temp); // move out by the clip_near value c_trace(cameraTPos,temp2,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS)); if(trace_hit == 1) { // offset from that target along the vector vec_set(cameraTPos,target); // offset from the wall along normal by the near clipping dist vec_normalize(normal,(camera.clip_near/2)); vec_add(cameraTPos,normal); // draw_text("HIT_1",30,300,vector(123,123,200)); } else { // rotate temp back the other dir twice as much.. vec_rotate(temp,vector(-180,0,0)); vec_set(temp2,cameraTPos); vec_add(temp2,temp); // move out by the clip_near value c_trace(cameraTPos,temp2,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS)); if(trace_hit == 1) { // offset from that target along the vector vec_set(cameraTPos,target); // offset from the wall along normal by the near clipping dist vec_normalize(normal,(camera.clip_near/2)); vec_add(cameraTPos,normal); // draw_text("HIT_2",30,300,vector(123,123,200)); } }
}
// Smooth out transition... vec_diff(temp,cameraTPos,camera.x); var vscale = clamp((time_step*0.5),0.001,1); vec_scale(temp,vscale); vec_add(camera.x,temp);
// calc angle from camera to target... vec_diff(temp,pFocus.x,cameraTPos); vec_to_angle(cameraTAng,temp); // camera target angle looks at focus center vec_add(cameraTAng, vecChaseAngOff.pan); // tweak it // Smooth out rotation... vec_diff(temp,cameraTAng,camera.pan); temp[0] = ang(temp[0]); // note! only pan is needed in this game! vec_scale(temp,vscale); vec_add(camera.pan,temp); // vec_set(camera.pan,cameraTAng.pan); }
if (camMode==2) // cockpit view { //set(pFocus,INVISIBLE); // You might want to set this to on if using dashboard bitmap vec_set(camera.pan, pFocus.pan); vec_set(camera.x, pFocus.x); // raise seat and move to driver side vec_set(temp, vecDriverOffset); vec_rotate(temp, pFocus.pan); vec_add(camera.x, temp); } //toggle camera if (KEY_CAMERA || JOY_CAMERA) { while (KEY_CAMERA || JOY_CAMERA) { wait(1); } camMode+=1; if (camMode>2) { camMode=0; } // reset if previously rolled around vec_set(camera.pan, cam_ang); } wait(1); } }
////////////////////////////////////////////////////////////// // assign this to terrain for multitexturing, uses 2nd skin as detail map action ffp_terr_detail() { detail_size = 16; }
////////////////////////////////////////////////////////////// // assign this to MDLs when user is to drive on them action MakePoly() { set(my,POLYGON); }
var StopWatchOn;
function Stopwatch_startup() { while (1) { if (StopWatchOn) timerSeconds+= time_step/16; speed_and_time(); //cg wait(1); } }
function ToggleStopwatch() { StopWatchOn = !StopWatchOn; }
////////////////////////////////////////////////////////////// // main function main() { video_mode=7; //800x600 shadow_stencil= ON; d3d_autotransparency = ON; vec_set(d3d_lodfactor,vector(35,60,75)); // default LOD switches
on_t = ToggleStopwatch; on_f1 = help_me; on_h = EventImpact; on_i = EventHorn;
cg_start(); init_normal(); // NM SHADER wait(1); level_load(levelname); // show title screen and spin camera
while(pFocus==NULL){wait(1);}
// activate real camera camMode = 1; set(physics_panel,VISIBLE); }
action Prop() { phent_settype(my, PH_RIGID, PH_BOX); phent_setdamping(my, 10, 30); } psysics_car.cCode:
//-------------------------------------------------------------- // Normal Mapping Shader // // Matt_Aufderheide, Bloodline, William, xXxGuitar511 // ------------------------------------------------------------- // title: Normal Mapping Shader // text: - // -------------------------------------------------------------
// entry: FX File: STRING* fxNM = "NM.fx"; STRING* MyAppTitle = "Normal Mapping Shader";
// section: Ambient Lighting: // enable: Faked Dynamics #define staFake // enable: Ambience #define staAmb
MATERIAL* comics = { ambient_blue = 100; ambient_green = 100; ambient_red = 100; albedo = 0; }
MATERIAL* mat_NM = { // section: Diffuse: // entry: Red diffuse_red = 255; // entry: Green diffuse_green = 255; // entry: Blue diffuse_blue = 255; // section: Ambient: // entry: Red ambient_red = 16.0; // entry: Green ambient_green = 16.0; // entry: Blue ambient_blue = 16.0; // // section: Sun: // // entry: Red // specular_red = 64.0; // // entry: Green // specular_green = 64.0; // // entry: Blue // specular_blue = 64.0; // section: Static Lighting: // entry: Red emissive_red = 255.0; // entry: Green emissive_green = 255.0; // entry: Blue emissive_blue = 255.0; // flags = tangent | enable_render; effect = fxNM; //event = checkLight; }
function effect_startup() { effect_load(mat_NM, fxNM); // var SLF; while(1) { SLF = 0; #ifdef staAmb SLF += 1; #endif #ifdef staFake SLF += 2; #endif // vec_set(mat_NM.specular_blue, sun_color); mat_NM.skill1 = pixel_for_vec(nullvector, SLF*10, 8888); wait(1); } }
//function checkLight() //{ // vec_set(temp, my.x); // temp.z -= floor_range; // c_trace(my.x, temp, ignore_me | scan_texture); // mtl.skill1 = pixel_for_vec(tex_color, tex_light, 8888); //}
#define _Red skill1 #define _Green skill2 #define _Blue skill3 #define _Range skill4 // action: Dynamic Light // text: - // skill1: Red 128 // skill2: Green 128 // skill3: Blue 128 // skill4: Range 300 action DLight() { my.red = my._Red; my.green = my._Green; my.blue = my._Blue; my.lightrange = my._Range; set(my,LIGHT); }
void init_normal() { effect_startup(); }
/* action SpinMe() { while(1) { my.material = mat_NM; my.pan -= 2 * time_smooth; wait(1); } } */
// END NORMALMAPPING SHADER
////////////////////////////////////////////////////////////// // Car constants var maxTorque= 1000; //1200 // maximum torque applied to rear wheels var maxTorqueBrake=1000; // this will be applied to rear wheels when hitting brakes or handbrake var maxAngSpeed= 70; //70 // max. angular speed of wheels; max linear speed depends on wheel radius var massWheel= 30; // mass per wheel var massChassis= 10; // mass for chassis lighter than wheels so it doesn't tilt var fricWheel= 100; //100 // friction of wheels -god for "in the water" var fricChassis= 20; // friction of chassis (low to avoid getting stuck on ramps var dampChassis= 5; // damping lin/ang for chassis var dampWheel= 15; //15 // damping ang for wheels var suspensionERP= 95000; //90000; // how quickly shocks are reduced to correct position (100,000 max, 0: never) var suspensionCFM= 250; //500 // how far shocks can overshoot (0: never, 100,000 max) var jumpRechargeDelay=1.5; //1.5 // time before user is allowed to jump again in secs var jumpForce= 3000; //3000; // force multiplier for jumps var gravity=1800; //2000; // gravity along -Z axis var bDentCar=1; // when set to 1 deform car on impact
////////////////////////////////////////////////////////////// // Steering constants var accelKeyboard=2; // acceleration multiplier for key control var accelSteering=3; // acceleration multiplier for steering key control VECTOR* joyNullzone = { x=20; y=20; } // 0..255 x and y direction center range for joystick
////////////////////////////////////////////////////////////// // these values depend on MDL and WMP where car is located var vecUp[3]= {0,0,1}; // up axis, usually +Z var vecRight[3]= {0,-1,0}; // chassis right axis var vecHookOffset[3]= {0,-15,40}; // this is offset from chassis center where lifter hook will be installed var vecDriverOffset[3]= {-35,10,34}; // where camera will be located relative to chassis center (cockpit) var vecChaseOffset[3]= {-150,0,60}; // where camera will be located relative to chassis center (chase) ANGLE vecChaseAngOff; // angle tweak of the chase camera
#define NUM_TRACKS 1 //400; // number of tire tracks #define CRASH_SPEED 100 // head-on impact above this speed causes wheels to come off ////////////////////////////////////////////////////////////// // Controller setup
#define KEY_FWD key_w // Forward #define KEY_BWD key_s // Backward #define KEY_LEFT key_a // Left #define KEY_RIGHT key_d // Right #define KEY_HORN key_h // Push horn #define KEY_LIFT key_l // Activate Lift #define KEY_JUMP key_e // Turbo Boost ;-) #define KEY_BRAKE key_space // Pull Handbrake
var USE_GAMEPAD= 0; // Treat joystick as absolute device #define JOY_JUMP joy_1 // Turbo Boost ;-) #define JOY_BRAKE joy_2 // Pull Handbrake #define JOY_LIFT joy_4 // Activate lift #define JOY_HORN joy_5 // Push horn #define JOYRAW_Y joy_raw.y // Forward/Backward axis on joystick #define JOYRAW_X joy_raw.x // Left/right axis on joystick
////////////////////////////////////////////////////////////// // physics global vars
var DoShutdown=0; // set to 1 and wait a while before reloading level var DoSteering=1; // set to 1 to enable all controls 0 for pause
var linSpeed; // car speed in XY var downSpeed; // car speed in Z direction var angSpeed; // current wheel angular speed along y axis of wheel var targetSpeed=0; // desired angular speed (if torque permits) var targetSteer=0; // desired steering angle
ENTITY* pChassis; //our car objects ENTITY* pFL; ENTITY* pFR; ENTITY* pRL; ENTITY* pRR; ENTITY* pHook; // hook for lifting car up var wheelFL; var wheelFR; // constraint handles var wheelRL; var wheelRR;
var handleLift=0; // handle to crane lifting up car var jumping=0; // time left in jump var hornPlaying=0; // on or off var brakePlaying=0; // on or off var wheelCounter=0; // # of initialized wheels
var trackLen =20; // length of treadmark in quants var arrpTracks[NUM_TRACKS]; // cyclic buffer of track entities (handles) var currTrack=0; // current track number var lastPos[3]; // position of chassis in last frame var timerSeconds; // a simple stopwatch, can be removed ////////////////////////////////////////////////////////////////////////////////////////// // Resources SOUND* engine_wav = "engine.wav"; // player's engine sound SOUND* horn_wav = "horn.wav"; // player's horn SOUND* crash_wav = "crash.wav"; // player's crashing sound SOUND* tires_wav = "tires.wav"; // tires squealing SOUND* flap_wav = "lp_flap.wav"; // tires squealing
var hTireSnd_n; // handle to sound playing
BMAP* bmpSmoke= "smoke.tga";
////////////////////////////////////////////////////////////////////////////////////////// // Includes #include "physics_init.c" // all car init functions #include "physics_events.c" // all car event & particle functions
////////////////////////////////////////////////////////////////////////////////////////// // Some status data var noTorque=0; /* PANEL* physics_panel = { pos_x = 200; pos_y = 4; flags=refresh; //digits = 0,20,8,fontArial,1,linSpeed; // car speed digits = 0,40,8,fontArial,1000,timerSeconds; } */ /* cg text physics_text { pos_x=50; pos_y=24; flags = narrow, TRANSLUCENT; font= fontArial;
strings=2; string= "Speed (km/h):", "Timer ['T'] (msec):"; } */
////////////////////////////////////////////////////////////////////////////////////////// // Car control
function SpeedControl() { var direction; var usejoy=0; while (1) { if (DoShutdown) { return; } // quitting? if (!DoSteering) // currently pausing? { wait(1); continue; }
if (JOYRAW_Y<-joyNullzone.y || JOYRAW_Y>joyNullzone.y) { // treat joystick as absolute device which is more // like a keyboard than a joystick if (USE_GAMEPAD) { usejoy=0; direction= -(JOYRAW_Y / 255); } else { usejoy=1; direction= -(JOYRAW_Y-joyNullzone.y)/(255-joyNullzone.y); } } else { usejoy=0; direction= (KEY_FWD-KEY_BWD); } // if we drive in one direction and want to change direction, apply brakes // (angSpeed>0 checks if rear wheel is turning forward // direction<0 checks if user hits reverse key if ((angSpeed>5 && direction<0) || (angSpeed<-5 && direction>0)) { targetSpeed=0; // brake // press brakes quarter down when rolling at high speed if (abs(angSpeed)>0.25*maxAngSpeed) { phcon_setmotor(wheelRL, nullvector, vector(angSpeed*0.5, 0.5*maxTorqueBrake,0), nullvector); phcon_setmotor(wheelRR, nullvector, vector(angSpeed*0.5, 0.5*maxTorqueBrake,0), nullvector); if (abs(angSpeed)>0.50*maxAngSpeed) { EventBrake(); // braking sound } } else { // we're already slow- apply max. units brake torque phcon_setmotor(wheelRL, nullvector, vector(0, maxTorqueBrake,0), nullvector); phcon_setmotor(wheelRR, nullvector, vector(0, maxTorqueBrake,0), nullvector); } } else { var oldSpeed; oldSpeed= targetSpeed; // regular driving if (usejoy) { targetSpeed = maxAngSpeed*direction; //absolute value for stick } else { // speed up over time for keyboard (relative acceleration) targetSpeed += direction*accelKeyboard* time_step; }
var torque; torque=maxTorque; // damp down speed over time if no key pressed if (!usejoy && direction==0) { targetSpeed *=1-(time_step*0.02); torque=maxTorque/2; if (abs(linSpeed)<20) // switch off opposing torque so we can roll down hills { torque=0; targetSpeed *=0.5;} } else { // use less torque to slow down or else we'll spin if (usejoy && abs(targetSpeed)<abs(angSpeed)) { torque=maxTorque/2; //targetSpeed *=0.5; }
} // max. reverse is 1/4 of forward speed targetSpeed= clamp(targetSpeed, -maxAngSpeed*0.25, maxAngSpeed); phcon_setmotor(wheelRL, nullvector, vector(targetSpeed, torque,0), nullvector); phcon_setmotor(wheelRR, nullvector, vector(targetSpeed, torque,0), nullvector); } if (KEY_BRAKE|| JOY_BRAKE) // handbrake { phcon_setmotor(wheelRL, nullvector, vector(0, maxTorqueBrake,0), nullvector); phcon_setmotor(wheelRR, nullvector, vector(0, maxTorqueBrake,0), nullvector); if (abs(linSpeed)>20) { EventBrake(); }// squeaky brakes }
EventJump(); // check for jump EventLift(); //process lifting wait(1); } }
////////////////////////////////////////////////////////////////////////////////////////// // Continuously calculate wheel rotational speed and store in global var function UpdateSpeed() { while (wheelCounter<4) { wait(1); } //wait for wheels to be init'ed
var players_engine; //handle for soundloop players_engine = snd_loop(engine_wav, 100,0); // play the engine sound in a loop snd_tune(players_engine, 80, 80, 0); //80% of real frequency
// check the rotation of the rear tires var rotSign; if(pRL.pan != pRR.pan) { // assume that the wheels are twisted 180 deg from each other rotSign = -1; } else { rotSign = 1; } var angRL; var angRR; VECTOR vecLin; while(1) { if (DoShutdown) { // quitting? snd_stop (players_engine); return; }
// get linear speed and tune engine sound phent_getvelocity(pChassis, vecLin, nullvector); //linear speed downSpeed= vecLin.z * 0.091; vecLin.z=0; // store Z separately linSpeed= vec_length(vecLin) * 0.091; // convert from quant/sec to kmh if (maxAngSpeed>0) { var freq; freq=300*abs(angSpeed)/maxAngSpeed; snd_tune(players_engine, 5, freq+80, 0); //80% of real frequency }
// grab angular velocity vector from rear wheels phent_getangvelocity(pRL, temp); angRL=temp[1]; phent_getangvelocity(pRR, temp); angRR=temp[1]; // store largest one if (abs(angRL)>abs(angRR)) { angSpeed= angRL; } else {angSpeed=rotSign * angRR; }
wait(1); } }
////////////////////////////////////////////////////////////////////// // the faster we go the more sensitive the car gets to steering. to make it easier for user // scale down his steering inputs the faster we go function CalcSteeringScale() { return (1-(abs(angSpeed)/(maxAngSpeed+60))); }
function SteerControl() { var direction=0; //delta change var usejoy; //using joystick for input? while (1) { if (DoShutdown) { return; } // quitting? if (!DoSteering) // currently pausing? { wait(1); continue; }
if (JOYRAW_X<-joyNullzone.x || JOYRAW_X>joyNullzone.x) { // treat gamepad as absolute device which is more // like a keyboard than a joystick if (USE_GAMEPAD) { usejoy=0; direction= (JOYRAW_X / 255); direction*= CalcSteeringScale(); } else { // using joystick usejoy=1; direction= (JOYRAW_X-joyNullzone.x) / (255-joyNullzone.x); direction*= CalcSteeringScale(); } } else { usejoy=0; direction= (KEY_RIGHT-KEY_LEFT); direction*= CalcSteeringScale(); }
// steering control if (0==usejoy) { targetSteer+= direction*accelSteering* time_step; } else { targetSteer= 30*direction; } targetSteer=clamp(targetSteer,-30,30);
if ((angSpeed>maxAngSpeed*0.95) && abs(targetSteer)>7) { EventBrake(); // play squeaky tires }
if (direction!=0) { phcon_setparams2(wheelFL, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0)); phcon_setparams2(wheelFR, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0)); } else { targetSteer*=1-(time_step*0.25); if (abs(targetSteer)<1) { targetSteer=0; } // force to 0 phcon_setparams2(wheelFL, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0)); phcon_setparams2(wheelFR, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0)); }
if (KEY_HORN || JOY_HORN) { EventHorn(); //sound horn } wait(1); } }
///////////////////////////////////////////////////////////////////////////////////////// // CarControl: Assigning this to your car's chassis is all you have to do //////////////////////////////////////////////////////////////////// action CarInit() { // build a car and wait til all wheels are ready ChassisInit(); //my.material = mat_metal; my.material = mat_NM; // Normal mapping shader
while (wheelCounter<4) { wait(1); } UpdateSpeed(); // update rear wheel speed (continuous) SpeedControl();// change speed (continuous) SteerControl();// change heading (continuous) }
|
|
|
|