Drive a Lamborghini in FreeBasic

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Drive a Lamborghini in FreeBasic

Post by angros47 »

Can you drive a Lamborghini Diablo?
Image


Can you drive it at night?
Image



And, most important: can you drive it in less than 60 lines of code?

Code: Select all

#include "minib3d.bi"

screen 18, 32, , &h02	
Graphics3d 640,480,32,1,1

var 	camera=createcamera()
	moveentity camera,0,100,0
	CameraClsColor camera,0,0,255
var 	light=createlight()
	RotateEntity light,-45,45,0
	AmbientLight 32,32,32
	
var	terr=LoadTerrain( "hmap_1024.bmp" )
	ScaleEntity terr,40,20,40
	EntityTexture terr, LoadTexture("Moss.bmp")

var 	car=createpivot()
var 	car2=loadmesh("lamborgini.3ds",car)
	rotatemesh car2,90,0,0


EntityRadius car,2.5
EntityType car,2

EntityType terr,1


Collisions 2,1,2,2
	moveentity car,2000,100,-2000

dim as single speed, dist,xx,yy,zz
speed=.1
do
	'Directions
	if MultiKey(&h48) then speed=speed+.1
	if MultiKey(&h50) then speed=speed-.1
	if MultiKey(&h4b) then TurnEntity car,0,1,0
	if MultiKey(&h4d) then TurnEntity car,0,-1,0
	MoveEntity car,0,-4,speed

	xx=CollisionNX(car,CountCollisions(car))
	yy=CollisionNY(car,CountCollisions(car))
	zz=CollisionNZ(car,CountCollisions(car))

	RotateEntity car2,-57*ASin(CollisionNZ(car,CountCollisions(car))*Cos(-EntityYaw(car)/57)), 0, 57*ASin(CollisionNZ(car,CountCollisions(car))*Sin(-EntityYaw(car)/57))
	PointEntity camera,car
	dist=EntityDistance (camera,car)
	If  Dist>100 Then MoveEntity camera,0,1,0.1*(Dist-100)

	updateworld
	renderworld
	flip
loop until MultiKey(1)

Download it here:
http://www.sendspace.com/file/1c9927

Using MiniB3D (included), both day and night versions.
JohnK
Posts: 279
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Post by JohnK »

Another little cool one. Is it possible to have minib3d calculate surface normals so the lighting is more realistic (currently lighting is reflected off each whole polygon, normally you would use Phong, or Gourand, shading. It is the line
var terr=LoadTerrain( "hmap_1024.bmp" )

Also, is VAR a keyword in FreeBasic?
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

JohnK wrote:Also, is VAR a keyword in FreeBasic?
Var declares a variable as whatever type is returned by the constructor or source type.

Code: Select all

Dim as Integer X=5

Var Y = X
-Vince
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

JohnK wrote:Also, is VAR a keyword in FreeBasic?
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgVar

Joshy
JohnK
Posts: 279
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Post by JohnK »

Those devs are just plain cool..
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Post by angros47 »

JohnK wrote:Another little cool one. Is it possible to have minib3d calculate surface normals so the lighting is more realistic (currently lighting is reflected off each whole polygon, normally you would use Phong, or Gourand, shading.)?
I'd like to do it, but it's not so easy: in fact, terrain is rendered using ROAM (Real-time Optimally Adapting Meshes), and every triangle is generated by a recursive algorithm: to use Phong or Gourand, minib3d should render, for each triangle, also adiacent ones (to get all vertices normals), and it would make the program much slower.

In MiniB3D source, you can have a look at terrain.cpp file, to understand how it works.
Post Reply