binary zoo
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 16, 2018, 03:36:29 PM

Login with username, password and session length
Search:     Advanced search
30167 Posts in 1158 Topics by 194 Members
Latest Member: RobertHedge
* Home Help Search Login Register
+  binary zoo
|-+  Game Development
| |-+  Guest Dev Blogs (Moderator: JDog053)
| | |-+  Small test of my terrains with a simple vehicle & suspension rig
Pages: [1] 2 3 Go Down Print
Author Topic: Small test of my terrains with a simple vehicle & suspension rig  (Read 11839 times)
Prime_8
1000 XP
*
Offline Offline

Posts: 1438



View Profile WWW
« on: May 02, 2012, 08:46:37 PM »

Small test of my terrains with a simple vehicle & suspension rig

coded in NB for speed of idea to code.
(sorce is in a .nb file. it is text format )
kept it simple for new NB users ..

but the idea is old to us DBP users for sure.


mainly i just wanted to help a user out and test my terrains .

only simple code but it workes better than i expected.

will post link to rar in a min .  Wink

vehtest2.rar   Grin



* shot.jpg (120.21 KB, 674x543 - viewed 270 times.)
« Last Edit: May 02, 2012, 08:52:54 PM by Prime_8 » Logged

Prime_8
1000 XP
*
Offline Offline

Posts: 1438



View Profile WWW
« Reply #1 on: May 02, 2012, 08:54:23 PM »


crappy code  Cheesy
Code:
// simple 4  wheel gound fallowing system , needs more optimisations .
// no max travel and bottoming out suspension systems , just crude wheel
// heights & chassis height
// chassis rotations are crude as well due to no bottoming systems.
// have fun .
// Truck is a dark matter mesh i have reworked for my purposes
// terrain is made by My PT3D tool .
// meshes formated / setup in my P3D for ease of use.

//some collision ids
TYPE_OBJECT = 1


//load the window
wnd = MakeWindowDX()
If Not wnd Then DebugError("Please update your DirectX")

SetWindowTitle wnd, "Nuclear Basic powered Terrain Crawler by Prime_8 "

cam = GetDefaultCamera()
vp = GetDefaultViewport()

PositionEnt cam, 0, 50, -50
PointEnt(cam , 0 ,0,0);
ResetEnt cam
Global light = GetDefaultLight()
//SetLightCastsShadows(light);
PositionEnt light, -50, 50, -50
ResetEnt light

Dim ray[4];
Dim meshWheel[4];
Dim meshWheelHub[4];
Dim meshWheelHeight#[4]; floats
Global wheelAxlelHeight# = 0.49 ;
Global  AxelWidth# = 0.49 ;
Global  AxelDist# = 0.49 ;

Global mesh=0;

Global hits = 0;

Global moveIt = 0;
 
Global dirSteer = 0 ;

//setup basic collisions`
SetCollisions TYPE_OBJECT, TYPE_OBJECT //objects collide with other objects

//setup ground plane // ground1a.n3d
file$ = "ground1a.n3d"
Global plane = LoadAnimEnt(file) ; // = MakePlane(100,100)

// AddEntBoxShape plane, 100, 0.001, 100 //this creates a collider shape in the same shape as the plane
AddEntMeshShape plane
SetEntShapeAsCharacter plane, False //turn off character mode
SetEntMass plane, 0.0 //once the mass of an entity is set it will be under the influence of physics
//(effectively infinite to prevent being knocked out of the way by the cubes)
SetEntGravity(plane, 0.0 ); // GetEntPosY(plane)+5

CollisionEnt plane, TYPE_OBJECT //make the plane into a collider object

lockmsg$ = "Locked"
viewlock = True ;
oneshot = 1;

//main loop (continues until escape key is pressed)
While Not KeyHit(1)

//update the framerate display
Print "FPS: "+GetFPS() + " Hits: " + hits;
If Not hidetext
Print ""
Print "Use the arrow keys to move and the mouse to steer"
Print "Use 'o' to load a new truck model"
Print "Use ASWD to drive model "
Print "Use 'b' to change the background color"
Print "Use 'r' to reset the view if you get lost"
Print "Use 'm' to mount/unmount cam to the truck"
Print "Use 'v' to lock and unlock the view - current mode: "+lockmsg
Print " when locked the cam tracks the truck if one is loaded "
Print "Use 'c' to togle shadows :: note, it kills terrain vert color."
Print "Use 'h' to show/hide this text"
Print ""
Print "Press '1' to enter windowed mode"
Print "Press '2' to enter fullscreen mode"
Print "Press '3' to enter fullscreen exclusive mode"
EndIf

//handle the 'o' key
If KeyHit(24) Or oneshot = 1
oneshot = 0;
file$ = "4x4Rig.n3d";

If Len(file)

mesh = LoadAnimEnt(file)
EndIf

If Not mesh Then Notice2("Could not load model", wnd)
//SetEntCastsShadows(mesh);
wheelAxlelHeight# = 0.49 ; // you may have to edit this for your mesh
meshWheel[0] = FindEnt(mesh, "Wheel FL");
meshWheel[1] = FindEnt(mesh, "Wheel FR");
meshWheel[2] = FindEnt(mesh, "Wheel BL");
meshWheel[3] = FindEnt(mesh, "Wheel BR");

meshWheelHub[0] = FindEnt(mesh, "hub FL");
meshWheelHub[1] = FindEnt(mesh, "hub FR");
meshWheelHub[2] = FindEnt(mesh, "hub RL");
meshWheelHub[3] = FindEnt(mesh, "hub RR");
loadres = meshWheel[0] + meshWheel[1] + meshWheel[2] + meshWheel[3] ;
If Not loadres Then Notice2("Could not locate model parts", wnd);


GetEntPos( meshWheel[0] , ax1# , ay1#, az1#, True );
GetEntPos( meshWheel[1] , ax2# , ay2#, az2#, True );
AxelWidth# = Abs( VecLength3D( ax1# - ax2# , ay1# - ay2#, az1# - az2# ) );

GetEntPos( meshWheel[0] , ax1# , ay1#, az1#, True );
GetEntPos( meshWheel[2] , ax2# , ay2#, az2#, True );
AxelDist# = Abs(VecLength3D( ax1# - ax2# , ay1# - ay2#, az1# - az2# ) );

Reset3DTweening
SetMousePos 100, 100, wnd

EndIf
 
//handle background color picker ('b' key)
If KeyHit(48)

bgcolor = MakeDialogColor2( bgcolor, wnd );
SetViewportColor vp, bgcolor
SetMousePos 100, 100, wnd

EndIf

//handle camera reset ('r' key)
If KeyHit(19)

PositionEnt cam, 0, 50, -50
RotateEnt cam, 0, 0, 0

ResetEnt cam

scale# = 1
If mesh Then ScaleEnt(mesh,scale,scale,scale)

EndIf

//handle camera reset ('c' key)
If KeyHit(46)
If mesh 
If GetEntCastsShadows(mesh) 
SetEntCastsShadows(mesh, 0 );
Else
SetEntCastsShadows(mesh, 1 );;
EndIf

If GetLightCastsShadows(light) 
SetLightCastsShadows(light, 0 );
Else
SetLightCastsShadows(light, 1 );;
EndIf

SetEntUseVertexColor(mesh);
SetEntUseVertexColor(plane);

EndIf
EndIf

//handle camera reset ('m' key)
If KeyHit(50)
If mesh
If GetEntParent(cam) = mesh
SetEntParent(cam,0);
Else
SetEntParent(cam,mesh);
EndIf
EndIf
EndIf


//handle the hiding/showing of text ('h' key)
If KeyHit(35)
If hidetext
hidetext = False
Else
hidetext = True
EndIf
EndIf

//set window to windowed
If KeyHit(2) Then SetWindowFullscreen(wnd, False)

//set window to fullscreen standard
If KeyHit(3) Then SetWindowFullscreen(wnd, True, 0, 0, 0, 2)

//set window to fullscreen exclusive
If KeyHit(4) Then SetWindowFullscreen(wnd, True, 0, 0, 0, 1)

//if it's time to move the objects
If Do3DTweening()

If moveIt
  fireRays();
moveIt = 0;
RotateEnt( meshWheelHub[0]  ,0,0,0);
RotateEnt( meshWheelHub[1]  ,0,0,0);
dirSteer = 0 ;
EndIf


//scale the mesh up 'a'
If KeyDown(30)
If mesh
    //TurnEntLocal(mesh,0,-0.4,0);
  TurnEntLocal(meshWheelHub[0], 0 , -20 ,0 );
  TurnEntLocal(meshWheelHub[1], 0 , -20 ,0 );
  dirSteer = 1 ;
  moveIt = 1 ;
EndIf
EndIf

//handle the 'd' key
If KeyDown(32)
If mesh
    //TurnEntLocal(mesh,0,0.4,0);
  TurnEntLocal(meshWheelHub[0], 0 , 20 ,0 );
  TurnEntLocal(meshWheelHub[1], 0 , 20 ,0 );
  dirSteer = 2 ;
  moveIt = 2 ;
EndIf
EndIf

//scale the mesh up 'w'
If KeyDown(17)
If mesh
    MoveEnt(mesh,0,0,0.15);
 
  If dirSteer = 1 ;
  TurnEntLocal(mesh,0,-0.6,0);
  EndIf  
  If dirSteer = 2 ;
  TurnEntLocal(mesh,0,0.6,0);
  EndIf
  roll# = 5.0
  TurnEntLocal(meshWheel[0], roll# , 0 , 0 );
  TurnEntLocal(meshWheel[1], roll# , 0 , 0 );
  TurnEntLocal(meshWheel[2], roll# , 0 , 0 );
  TurnEntLocal(meshWheel[3], roll# , 0 , 0 );
  moveIt = 1 ;
EndIf
EndIf

//handle the 's' key
If KeyDown(31)
If mesh
    MoveEnt(mesh,0,0,-0.15);
  If dirSteer = 1 ;
  TurnEntLocal(mesh,0,0.6,0);
  EndIf  
  If dirSteer = 2 ;
  TurnEntLocal(mesh,0,-0.6,0);
  EndIf
  roll# = -5.0
  TurnEntLocal(meshWheel[0], roll# , 0 , 0 );
  TurnEntLocal(meshWheel[1], roll# , 0 , 0 );
  TurnEntLocal(meshWheel[2], roll# , 0 , 0 );
  TurnEntLocal(meshWheel[3], roll# , 0 , 0 );  
  moveIt = 1 ;
EndIf
EndIf



//if they press the "up" arrow
If KeyDown(200) Or KeyHit(200) Then MoveEnt(cam,0,0,1.5)

//if they press the "down" arrow
If KeyDown(208) Or KeyHit(208) Then MoveEnt(cam,0,0,-1.5)

//if they press the "left" arrow
If KeyDown(203) Or KeyHit(203) Then MoveEnt(cam,-1.5,0,0)

//if they press the "right" arrow
If KeyDown(205) Or KeyHit(205) Then MoveEnt(cam,1.5,0,0)

//handle animation speed up (+ key)
If KeyDown(13) Or KeyHit(13)
If mesh Then SetEntAnimSpeed( mesh, GetEntAnimSpeed(mesh)+0.05 )
EndIf

//handle animation slow down (- key)
If KeyDown(12) Or KeyHit(12)
If mesh Then SetEntAnimSpeed( mesh, GetEntAnimSpeed(mesh)-0.05 )
EndIf

//if we're in a view lock
If viewlock

If KeyHit(47) //if they hit the 'v' key
SetMousePos 100, 100, wnd    //set the mouse position
viewlock = False             //unset the view lock
lockmsg$ = "Unlocked"
EndIf
If mesh Then PointEnt(cam , GetEntPosX(mesh) , GetEntPosY(mesh) ,GetEntPosZ(mesh));

Else

//if they hit the 'v' key
If KeyHit(47)
lockmsg$ = "Locked"
viewlock = True         //set the view lock
Else

If MouseMove()

//get the turning offsets
xOff# = (MouseX(wnd) - 100) * 0.20
yOff# = (MouseY(wnd) - 100) * 0.20

//turn the entity
TurnEnt cam, 0, xOff, 0         //turn the entity on y axis
TurnEntLocal cam, yOff, 0, 0    //turn the entity on x axis

//set the position
SetMousePos 100, 100, wnd       //set the mouse position

EndIf

EndIf
EndIf

EndIf  //endif - it's time to move the objects

Sync
Wend

End();

/* to remember order of wheels .
meshWheel[0] = FindEnt(mesh, "Wheel FL");
meshWheel[1] = FindEnt(mesh, "Wheel FR");
meshWheel[2] = FindEnt(mesh, "Wheel BL");
meshWheel[3] = FindEnt(mesh, "Wheel BR");
*/

Function fireRays()
// ray[4];
hits = hits +1 ;
If mesh
hits = 0 ;
wheelActive = 0;
meanRayHeight# = 0 ;
For wheelActive = 0 To 3
ray[wheelActive] = MakeRay( GetEntPosX(meshWheel[wheelActive]) , GetEntPosY(meshWheel[wheelActive])+1000, GetEntPosZ(meshWheel[wheelActive]), GetEntPosX(meshWheel[wheelActive]) , GetEntPosY(meshWheel[wheelActive])-1000, GetEntPosZ(meshWheel[wheelActive]), TYPE_OBJECT,  0 );
If GetRayHitCount( ray[wheelActive] )
meshWheelHeight#[wheelActive] = GetRayHitPosY( ray[wheelActive] ,  0 ) ;
hits = hits +1 ;
EndIf
meanRayHeight# = meanRayHeight# + meshWheelHeight#[wheelActive];
// puts wheels at local terrain height 
KillRay(ray[wheelActive] );
Next ;

meanRayHeight# = meanRayHeight# / 4.0;
// position the chassis at the average tire height + 1/4 axle height . note very accurate but looks ok .
PositionEnt(mesh , GetEntPosX(mesh)  , meanRayHeight# + (wheelAxlelHeight#/4.0) , GetEntPosZ(mesh) ,1)
FAHD# =   meshWheelHeight#[0] - meshWheelHeight#[1] ; // front axle
RAHD# =   meshWheelHeight#[2] - meshWheelHeight#[3] ; // rear axle
MAHD# = (( FAHD# + RAHD# )/2.0 )  / AxelWidth# ;// mean left to right slope of veh
LRtheta# = ATan( -MAHD# );

FAHD# =   meshWheelHeight#[0] - meshWheelHeight#[2] ; // left side
RAHD# =   meshWheelHeight#[1] - meshWheelHeight#[3] ; // right side
MADD# = (( FAHD# + RAHD# )/2.0 )  / AxelDist# ; // mean fron to back slope of veh 
FBtheta# = ATan( -MADD# );

curY# = GetEntRotY(mesh , True);
RotateEnt(mesh,FBtheta ,curY,LRtheta );
// meshWheelHub[0] stores safe xz coords for wheels .. the hub pivots attached to body .
// only need to change heights .
For wheelActive = 0 To 3
PositionEnt( meshWheel[wheelActive] , GetEntPosX(meshWheelHub[wheelActive]) , meshWheelHeight#[wheelActive] + wheelAxlelHeight# , GetEntPosZ(meshWheelHub[wheelActive]) , 1 );
Next
EndIf
EndFunction

Logged

T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #2 on: May 03, 2012, 06:15:35 AM »

Thats quite neat.

Have written many similar demo's myself.

A couple of issues though.

Pressing 3, "Fullscreen exclusive" mode, gives me a blank white screen.

Pressing 2 after three also gives a white screen.

But, pressing 2 after 1 gives a correct full screen mode.


Also, the car doesn't have any inertia ( forward velocity), it just stops dead when i let go of the key.


Apart from that it seems to work well.

Shadows were really cool.  Stencil's i'm guessing.


What physics engine does NB use ?


TMC
Logged
Prime_8
1000 XP
*
Offline Offline

Posts: 1438



View Profile WWW
« Reply #3 on: May 03, 2012, 09:39:45 AM »

lol . yeah . mode 3 , had a bug init after last nf / Nb update . will be fixed very soon .

~ i may put foux inertais later .

was more for me to test my terrain with ray picking .. and to help an other NB user see how ease setting a programatic rig for a car is to make.  ( i could have spent gays telling him in text .. but code is faster )

NF engine uses Bullet physics  ( 90%) of it ..  soon to be more & better in next NF / NB  build.

you can enable a object to have colission detections only , or simply give it a mass and now it is a default physics body , with a plethora of possible physics related settings . lol
Logged

fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13178



View Profile WWW Email
« Reply #4 on: May 03, 2012, 02:30:49 PM »

Nice.  Framerate barely made double figures here though lol Smiley
Logged

Prime_8
1000 XP
*
Offline Offline

Posts: 1438



View Profile WWW
« Reply #5 on: May 03, 2012, 08:16:24 PM »

my bad .. rename a few of the perlin textures , to stop em loading , and don't use shhadows . lol
i suppose the high poly terrain mesh dont help either . lol

Logged

fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13178



View Profile WWW Email
« Reply #6 on: May 03, 2012, 08:51:03 PM »

my bad .. rename a few of the perlin textures , to stop em loading , and don't use shhadows . lol
i suppose the high poly terrain mesh dont help either . lol
Just tried it again out of curiosity without those perlin textures and the framerate climbs to 40 fps.

What is interesting is that the FPS plummets to around 20 whenever it's having to calculate for the vehicle going over rough ground.  I'm very surprised to see a drop like that.  There must be some funky maths going on there Smiley
Logged

Prime_8
1000 XP
*
Offline Offline

Posts: 1438



View Profile WWW
« Reply #7 on: May 04, 2012, 12:40:06 PM »

new video showing realtime headlights and fake inertia .


::
fps bost yeah .. but  but there is no extra math during rough vs flat .. terrain mean slope(s) is calculated if any input ( or velocity) remians.

if truck is still , truly still  all that maths stops untill next move .
in new version i have simple velocity with a decay value .
but whe velocity hits 0 , all math stops .


wat i suspect is the poly count is changing slightly in view... LOL
« Last Edit: May 04, 2012, 12:48:03 PM by Prime_8 » Logged

T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #8 on: May 05, 2012, 07:07:49 AM »

Those headlights are really cool.  Grin

I don't know why you're using Fake Inertia though.

Surely if you're using a physics engine then applying Linear Velocity is standard.

Either applying a force or an impulse on the chassis in the direction it's facing is all thats needed.

You'd be able to get the car airbourne then.

Which is what i really wanted to do in your demo.

TMC
Logged
Prime_8
1000 XP
*
Offline Offline

Posts: 1438



View Profile WWW
« Reply #9 on: May 05, 2012, 05:42:51 PM »

no physcis in this , only collission .

Matt never added what i need to make proper wheel / axel colissions . LOL

not yet any how . lol

i'll figure out travel limits and then add vertical inertias . lol
the trick will be to add feed back from compression .
« Last Edit: May 05, 2012, 05:45:55 PM by Prime_8 » Logged

T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #10 on: May 05, 2012, 06:14:33 PM »

Ahh ok.   Roll Eyes

That explains it then.

Pity.

TMC

Logged
fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13178



View Profile WWW Email
« Reply #11 on: May 05, 2012, 07:24:01 PM »

no physcis in this , only collission .

Matt never added what i need to make proper wheel / axel colissions . LOL

not yet any how . lol

i'll figure out travel limits and then add vertical inertias . lol
the trick will be to add feed back from compression .
I thought you were using C++ with NF?  If so then you might be better using and existing physics lib rather than waiting for Matt to add what you need?
Logged

Prime_8
1000 XP
*
Offline Offline

Posts: 1438



View Profile WWW
« Reply #12 on: May 06, 2012, 04:19:06 PM »

yeah , i could use C++ . but tbullet is allready built in .

i tried relinking bullet myself and it clashes with teh existing one .

there is supposed to be joints and wheels and such with examples in next update . LOL

i'll have crack at this soon .

(i poked matt re not having car physics sample )lol
Logged

T_M_C
1000 XP
*
Offline Offline

Posts: 3000

TMC


View Profile Email
« Reply #13 on: May 21, 2012, 11:41:23 AM »

Hey Prime.

Do you have any links to landscape texturing tutorials.

Tileing textures and the like.

Cheers.

TMC
Logged
fog
Zookeeper
1000 XP
*
Offline Offline

Posts: 13178



View Profile WWW Email
« Reply #14 on: May 21, 2012, 05:06:35 PM »

Do you have any links to landscape texturing tutorials.

Tileing textures and the like.
And what do we need this for?  A new project? Smiley
Logged

Pages: [1] 2 3 Go Up Print 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Simple Audio Video Embedder
Valid XHTML 1.0! Valid CSS!