fb:porticula NoPaste
OpenGL Car Show [Cartuning]
Uploader: | Volta |
Datum/Zeit: | 11.02.2008 19:45:41 |
' Car Show OpenGL Demo! v1.0
' (C) 2008 Innova and Kristopher Windsor
' http://www.freebasic.net/forum/viewtopic.php?p=91830#91830
'Cartuning by Volta :))
#include "GL/gl.bi"
#include "GL/glu.bi"
Const screenx = 800, screeny = 600
Const true = -1, false = 0, pihalf = Atn(1) * 2
Type camera_type
As Double eye(1 To 3)
As Double see(1 To 3)
As Double up(1 To 3)
End Type
Type coord_type
As Double x, y
End Type
Dim Shared LightDiffuse(0 To 3) As Single => {3, 3, 3, 1}
Dim Shared LightPosition(0 To 3) As Single => {0, 0, 0, 1}
Dim Shared As String Key
Dim Shared As camera_type camera
Sub start
Screenres screenx, screeny, 32,, 2
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 35.0, screenx / screeny, .01, 8
glMatrixMode GL_MODELVIEW
glLoadIdentity
glClearColor 0, 0, 0, 1
'properly handles overlapping polygons (draw order for layering)
glEnable GL_DEPTH_TEST
glEnable GL_LIGHT1
glLightfv GL_LIGHT1, GL_DIFFUSE, @LightDiffuse(0)
glEnable GL_LIGHTING
glEnable GL_COLOR_MATERIAL
Randomize Timer
End Sub
Sub show_car (x As Double, y As Double, spin As Double)
Const w = .4, h = .6
#define c1 glColor3d (1, 0, 0)
#define c2 glColor3d (.2,.2,.2)
#define c3 glColor3d (.25, .25, .9)
#define c4 glColor3d (.1, .15, .15)
#macro v(px, py, pz)
Scope
Dim As Double a, d, px2
px2 = px * w
a = Atan2(py, px2) + spin
d = Sqr(px2 * px2 + py * py)
glVertex3d x + Cos(a) * d, y + Sin(a) * d, pz * h
End Scope
#endmacro
'Heckblech
c1
glNormal3f 0, -1, 0
v(1, -.98, .6)
v(-1, -.98, .6)
v(-1, -1, .3)
v(1, -1, .3)
'Bremslichter
glColor3d (1, .2, .2)
glNormal3f 0, 1, 0
v(-.95, -.99, .57)
v(-.8 , -.99, .57)
v(-.8 , -1, .49)
v(-.95, -1, .49)
glNormal3f 0, -1, 0
v(.95, -.99, .57)
v(.8 , -.99, .57)
v(.8 , -1, .49)
v(.95, -1, .49)
'Nummernschild hinten
glColor3d (1, 1, 1)
glNormal3f 0, -1, 0
v(.3, -1.01, .4)
v(-.3, -1.01, .4)
v(-.3, -1.01, .3)
v(.3, -1.01, .3)
'Spoiler
c2
glNormal3f 0, -1, 0
v(1, -.98, .6)
v(-1, -.98, .6)
v(-1, -1.04, .7)
v(1, -1.04, .7)
'Heckhaube
c1
glNormal3f 0, 0, 1
v(-1, -.7, .6)
v(1, -.7, .6)
v(1, -.98, .6)
v(-1, -.98, .6)
'Heckfenster
c3
glNormal3f 0, -1, 0
v(.72, -.5, 1)
v(-.72, -.5, 1)
v(-1, -.7, .6)
v(1, -.7, .6)
'Dach
c1
glNormal3f 0, 0, 1
v(-.72, -.5, 1)
v(.72, -.5, 1)
v(.72, 0, 1)
v(-.72, 0, 1)
'Frontscheibe
c3
glNormal3f 0, 1, 0
v(.72, 0, 1)
v(-.72, 0, 1)
v(-1, .4, .6)
v(1, .4, .6)
'Fronthaube
c1
glNormal3f 0, 0, 1
v(-1, .4, .6)
v(1, .4, .6)
v(1, .95, .6)
v(-1, .95, .6)
'Frontblech
c1
glNormal3f 0, 1, 0
v(1, .95, .6)
v(-1, .95, .6)
v(-1, 1, .3)
v(1, 1, .3)
'Scheinwerfer
glColor3d (1, 1, 0)
glNormal3f 0, 1, 0
v(.95, .97, .55)
v(.6 , .97, .55)
v(.6 , .982, .45)
v(.95, .982, .45)
glNormal3f 0, 1, 0
v(-.95, .97, .55)
v(-.6 , .97, .55)
v(-.6 , .982, .45)
v(-.95, .982, .45)
'Nummernschild vorne
glColor3d (1, 1, 1)
glNormal3f 0, 1, 0
v(.3, 1.01, .35)
v(-.3, 1.01, .35)
v(-.3, 1.01, .25)
v(.3, 1.01, .25)
'linke Seite
c1
glNormal3f -1, 0, 0
v(-1, -.98, .6)
v(-1, -1, .3)
v(-1, 1, .3)
v(-1, .95, .6)
c3'Fenster
glNormal3f -1, 0, 0
v(-.72, -.5, 1)
v(-1, -.7, .6)
v(-1, .4, .6)
v(-.72, 0, 1)
'rechte Seite
c1
glNormal3f 1, 0, 0
v(1, -.98, .6)
v(1, -1, .3)
v(1, 1, .3)
v(1, .95, .6)
c3'Fenster
glNormal3f 1, 0, 0
v(.72, -.5, 1)
v(1, -.7, .6)
v(1, .4, .6)
v(.72, 0, 1)
'Reifen vorn links
c2
glNormal3f -1, 0, 0
v(-1, .59, .1)
v(-1, .65, 0)
v(-1, .7, 0)
v(-1, .76, .1)
' c2
glNormal3f -1, 0, 0
v(-1, .55, .3)
v(-1, .59, .1)
v(-1, .76, .1)
v(-1, .8, .3)
c4
glNormal3f -1, 0,0
v(-1, .55, .3)
v(-.8, .55, .3)
v(-.8, .59, .1)
v(-1, .59, .1)
glNormal3f -1, 0,0
v(-1, .59, .1)
v(-.8, .59, .1)
v(-.8, .65, 0)
v(-1, .65, 0)
glNormal3f -1, 0,0
v(-1, .65, .01)
v(-.8, .65, .01)
v(-.8, .7, .01)
v(-1, .7, .01)
glNormal3f -1, 0,0
v(-1, .7, 0)
v(-.8, .7, 0)
v(-.8, .76, .1)
v(-1, .76, .1)
glNormal3f -1, 0,0
v(-1, .76, .1)
v(-.8, .76, .1)
v(-.8, .8, .3)
v(-1, .8, .3)
'Reifen vorn rechts
c2
glNormal3f 1, 0, 0
v(1, .59, .1)
v(1, .65, 0)
v(1, .7, 0)
v(1, .76, .1)
' c2
glNormal3f 1, 0, 0
v(1, .55, .3)
v(1, .59, .1)
v(1, .76, .1)
v(1, .8, .3)
c4
glNormal3f 1, 0,0
v(1, .55, .3)
v(.8, .55, .3)
v(.8, .59, .1)
v(1, .59, .1)
glNormal3f 1, 0,0
v(1, .59, .1)
v(.8, .59, .1)
v(.8, .65, 0)
v(1, .65, 0)
glNormal3f 1, 0,0
v(1, .65, .01)
v(.8, .65, .01)
v(.8, .7, .01)
v(1, .7, .01)
glNormal3f 1, 0,0
v(1, .7, 0)
v(.8, .7, 0)
v(.8, .76, .1)
v(1, .76, .1)
glNormal3f 1, 0,0
v(1, .76, .1)
v(.8, .76, .1)
v(.8, .8, .3)
v(1, .8, .3)
'Reifen hinten links
c2
glNormal3f -1, 0, 0
v(-1, -.59, .1)
v(-1, -.65, 0)
v(-1, -.7, 0)
v(-1, -.76, .1)
' c2
glNormal3f -1, 0, 0
v(-1, -.55, .3)
v(-1, -.59, .1)
v(-1, -.76, .1)
v(-1, -.8, .3)
c4
glNormal3f -1, 0,0
v(-1, -.55, .3)
v(-.8, -.55, .3)
v(-.8, -.59, .1)
v(-1, -.59, .1)
glNormal3f -1, 0,0
v(-1, -.59, .1)
v(-.8, -.59, .1)
v(-.8, -.65, 0)
v(-1, -.65, 0)
glNormal3f -1, 0,0
v(-1, -.65, .01)
v(-.8, -.65, .01)
v(-.8, -.7, .01)
v(-1, -.7, .01)
glNormal3f -1, 0,0
v(-1, -.7, 0)
v(-.8, -.7, 0)
v(-.8, -.76, .1)
v(-1, -.76, .1)
glNormal3f -1, 0,0
v(-1, -.76, .1)
v(-.8, -.76, .1)
v(-.8, -.8, .3)
v(-1, -.8, .3)
'Reifen hinten rechts
c2
glNormal3f 1, 0, 0
v(1, -.59, .1)
v(1, -.65, 0)
v(1, -.7, 0)
v(1, -.76, .1)
' c2
glNormal3f 1, 0, 0
v(1, -.55, .3)
v(1, -.59, .1)
v(1, -.76, .1)
v(1, -.8, .3)
c4
glNormal3f 1, 0,0
v(1, -.55, .3)
v(.8, -.55, .3)
v(.8, -.59, .1)
v(1, -.59, .1)
glNormal3f 1, 0,0
v(1, -.59, .1)
v(.8, -.59, .1)
v(.8, -.65, 0)
v(1, -.65, 0)
glNormal3f 1, 0,0
v(1, -.65, .01)
v(.8, -.65, .01)
v(.8, -.7, .01)
v(1, -.7, .01)
glNormal3f 1, 0,0
v(1, -.7, 0)
v(.8, -.7, 0)
v(.8, -.76, .1)
v(1, -.76, .1)
glNormal3f 1, 0,0
v(1, -.76, .1)
v(.8, -.76, .1)
v(.8, -.8, .3)
v(1, -.8, .3)
End Sub
Sub go
Dim As Double angle
'coords are set for bird's eye view
'top left of map is at (0, 0, 0)
'all parts of map are 1un cubed
glClear GL_DEPTH_BUFFER_BIT Or GL_COLOR_BUFFER_BIT
glLoadIdentity
LightPosition(0) = 0
LightPosition(1) = 0
LightPosition(2) = -1
glLightfv GL_LIGHT1, GL_POSITION, @LightPosition(0)
angle = -Timer * .4
With camera
.eye(1) = Cos(angle) * 3
.eye(2) = Sin(angle) * 3
.eye(3) = .8
.see(1) = 0
.see(2) = 0
.see(3) = .4
.up(1) = 0
.up(2) = 0
.up(3) = 1
gluLookat .eye(1), .eye(2), .eye(3), .see(1), _
.see(2), .see(3), .up(1), .up(2), .up(3)
End With
glBegin GL_QUADS
'ground
glColor3d 0, .4, .2
glNormal3f 0, 0, 1
glVertex3d -1, -1, 0
glVertex3d 1, -1, 0
glVertex3d 1, 1, 0
glVertex3d -1, 1, 0
show_car 0, 0, .5
glEnd
Flip
End Sub
'Sub main
start
Do
go
Sleep 10
Key = Inkey
Loop Until Key = Chr(27)
'End Sub