Straße

Übersicht BlitzBasic Blitz3D

Neue Antwort erstellen

Flori-D

Betreff: Straße

BeitragDo, Mai 20, 2004 12:47
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi.Wie mache ich am besten ne Straße?Habs mit Sprites versucht aber das wird galbe nichts.Wie kann ich das am besten machen?
BB is Macht!

Homepage: www.flori-d.de

Markus2

BeitragDo, Mai 20, 2004 14:05
Antworten mit Zitat
Benutzer-Profile anzeigen
Am einfachsten wäre für dich wenn du dir Einzelteile der
Strecke erstellst in nem 3D Programm und diese in BB dann zusammen
legst . (CopyEntity!)

Flori-D

BeitragDo, Mai 20, 2004 14:08
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich hab zwar Milkshape3D aber ich muss sagen ich bin absoluter loser in der beziehung.Ich krieg damit nicht mal ne ordentliche Straße hin.
BB is Macht!

Homepage: www.flori-d.de

Markus2

BeitragFr, Mai 21, 2004 0:47
Antworten mit Zitat
Benutzer-Profile anzeigen
Dann versuche es doch direkt in BB .

1 Mesh
4 Vertices
2 Dreiecke
1 Texture

ist doch nicht so schwer , zur NOT erst aufmalen !

Kurven sind auch nicht schwer wenn du das mit den UV
Texture Koordinaten verstanden hast .

Flori-D

BeitragFr, Mai 21, 2004 9:54
Antworten mit Zitat
Benutzer-Profile anzeigen
werds mal versuchen.
BB is Macht!

Homepage: www.flori-d.de
 

Omenaton_2

BeitragFr, Mai 21, 2004 12:10
Antworten mit Zitat
Benutzer-Profile anzeigen
Du kannst (falls das in dein Konzept paßt) die Straße als Textur machen. kein extra 3D-Objekt nötig. Einfach auf die Bodentextur die Straße drauf malen.

Flori-D

BeitragFr, Mai 21, 2004 12:14
Antworten mit Zitat
Benutzer-Profile anzeigen
Es soll nur ne grade Straße werden.Im enteffekt fährt man ein Auto(es wird immer schneller),dann wird ne Ampel rot man muss bremsen und dann wird die Reaktion angezeigt.
BB is Macht!

Homepage: www.flori-d.de

Markus2

BeitragFr, Mai 21, 2004 15:33
Antworten mit Zitat
Benutzer-Profile anzeigen
In dieses Beispiel kann man auf nem Terrain rum fahren und
eine Straße wird auch erzeugt .
Das AutoMesh hat die länge 1 und ist im Quelltext scaliert . 1cm=1
Texturen haste bestimmt selber .

Code: [AUSKLAPPEN]


;-----------------------------------

Graphics3D 800,600,16
SetBuffer BackBuffer()

;-----------------------------------

Global font=LoadFont("Tahoma",18)
SetFont font
Global FontY=18

;-----------------------------------

plane=CreatePlane()
planetxt=CreateTexture(64,64)
SetBuffer TextureBuffer(planetxt)
Color 128,128,128
Rect 0,0,64,64

Color 64,64,64
Rect 0,0,32,32
Rect 32,32,32,32

SetBuffer BackBuffer()
ScaleTexture planetxt,512,512

EntityTexture plane,planetxt

;------------------------------------------------------------------------------------ Boden
.Boden

Global boden = LoadTerrain("heightmap_256.bmp")
TerrainDetail boden, 3000, True

ScaleEntity boden, 50,1000,50
sx=256*50
sz=256*50
PositionEntity boden,-sx/2,0,-sz
Global bodentex = LoadTexture("terrain-1.jpg")

ScaleTexture bodentex,10,10
TerrainShading boden,1
EntityTexture boden,bodentex

;xxx=CreateCube()
;ScaleMesh xxx,0.5,0.5,0.5
;ScaleMesh xxx,150,150,150
;NameEntity xxx,"CUBE!"
;EntityPickMode xxx,2

;-----------------------------------

Global br1=CreateBrush()
Global br2=CreateBrush()
Global br3=CreateBrush()
Global br4=CreateBrush()
Global br5=CreateBrush()
Global br6=CreateBrush()
Global br7=CreateBrush()

Global tx1=LoadTexture("Texture\SBR.bmp",1+8+256)
Global tx2=LoadTexture("Texture\SBL.bmp",1+8+256)

BrushTexture br1,tx1
BrushTexture br2,tx2

;------------------------------------------------------------------------------------ Auto
.Auto

Type AutoType
 Field px#,py#,pz# ;Position
 Field Entity
 Field Laenge#
 Field Breite#
 Field Hoehe#
 Field BeschleunigungsKraft#
 Field Masse#
End Type

Global tAuto.AutoType=New AutoType

tAuto\Entity = LoadMesh("MR_D1_PorscheRot.3ds")
ScaleMesh tAuto\Entity,260,260,260
NameEntity tAuto\Entity,"Porsche"

tAuto\Laenge = MeshDepth (tAuto\Entity)/2
tAuto\Breite = MeshWidth (tAuto\Entity)/2
tAuto\Hoehe  = MeshHeight(tAuto\Entity)/2
tAuto\Masse = 1250
tAuto\BeschleunigungsKraft=0

tAuto\px = 0
tAuto\py = 100
tAuto\pz = 0

PositionEntity tAuto\Entity,tAuto\px,tAuto\py,tAuto\pz

;these are just for visual ref - not needed in calculation of rotations
Global pop = CreateCube()
ScaleEntity pop,5,400,5

Global pfront = CreateSphere(8)
EntityColor pfront ,0,255,0
ScaleEntity pfront,5,5,5

Global pback = CreateSphere(8) 
EntityColor pback,0,255,0
ScaleEntity pback,5,5,5

Global pleft = CreateSphere(8)
ScaleEntity pleft,5,5,5

Global pright = CreateSphere(8)
ScaleEntity pright,5,5,5

;----------------------------------------------------------------------------------

Dim st(100)

st(0)=MakeStreet()

 For i=1 To 60
  st(i)=CopyEntity(st(0))
  PositionEntity st(i),EntityX(st(i-1)),EntityY(st(i-1)),EntityZ(st(i-1))
  RotateEntity st(i),EntityPitch(st(i-1)),EntityYaw(st(i-1)),EntityRoll(st(i-1))
  MoveEntity st(i),0,0,512
  TurnEntity st(i),Rnd(-5,4),0,0
 Next

;------------------------------------------------------------------------------------ Kamera
.Kamera

Global camera = CreateCamera()
PositionEntity camera,0,256,-256
PointEntity camera,tAuto\Entity
CameraRange camera,1,1024*10

;-----------------------------------

Global light=CreateLight(camera)
PositionEntity light,EntityX(camera,True),EntityY(camera,True),EntityZ(camera,True),True
LightRange light,1000

;----------------------------------------------------------------------------------

Global msg$

;################################################################################################## Main

.Main
 MainLoop
 End

;################################################################################################## TEST

;While Not KeyHit(1)

; z=-JoyY()*20
; x=-JoyX()*2
; MoveEntity campiv,0,0,z
; TurnEntity campiv,0,x,0

; RenderWorld
; Flip
;Wend
;End

;##################################################################################################

Function MainLoop()

 Local Ende=False
 
 Repeat
  If DriveCar()=False Then Ende=True
 Until Ende=True

End Function

;##################################################################################################

Function DriveCar()

 Local Ret=False

 Local x#,y#,z#
 Local th#=0
 Local speed#=0

 Local turn#=0
 Local pitch#=0
 Local yaw#=0
 Local roll#=0

 Local frontheight#=0 ; height of terrain at midpoint front of vehicle
 Local backheight#=0 ; height of terrain at midpoint back of vehicle
 Local leftheight#=0 ; height of terrain at midpoint left side of vehicle
 Local rightheight#=0 ; height of terrain at midpoint right side of vehicle

 Repeat

 x# = EntityX (tAuto\Entity)
 z# = EntityZ (tAuto\Entity)
 y# = EntityY (tAuto\Entity)

 ;--------------------------------------------------------------------------------------------------

 ; check for keypress to turn Auto left/right
 turn = (KeyDown(203)) - (KeyDown(205))
 TurnEntity tAuto\Entity,0,turn,0
 yaw# = EntityYaw(tAuto\Entity)

 ; CALCULATE PITCH/ROLL ++++++++++++++++++++++++++++++++
 ;work out terrainheights at front/back/left/right of Auto
 anglenew# = yaw -90  ; what must be added to yaw to calculate front of vehicle's global x,z co-ords
 xnew# = x+Cos(anglenew)*tAuto\Laenge
 znew# = z+Sin(anglenew)*tAuto\Laenge
 frontheight# = MyTerrainY(Boden,xnew,y,znew,True); get the height at new x,y,z
 PositionEntity pfront,xnew,frontheight,znew ; a visual marker only - not neccessary for calculations

 anglenew# = yaw +90 ; what must be added to yaw to calculate back of vehicle's global x,z co-ords
 xnew# = x+Cos(anglenew)*tAuto\Laenge
 znew# = z+Sin(anglenew)*tAuto\Laenge
 backheight = MyTerrainY(Boden,xnew,y,znew)
 PositionEntity pback,xnew,backheight,znew

 anglenew# = yaw  ; what must be added to yaw to calculate midleft of vehicle's global x,z co-ords
 xnew# = x+Cos(anglenew)*tAuto\Breite
 znew# = z+Sin(anglenew)*tAuto\Breite
 Leftheight = MyTerrainY(Boden,xnew,y,znew)
 PositionEntity pleft,xnew,leftheight,znew

 anglenew# = yaw + 180 ; what must be added to yaw to calculate midright of vehicle's global x,z co-ords
 xnew# = x+Cos(anglenew)*tAuto\Breite
 znew# = z+Sin(anglenew)*tAuto\Breite
 rightheight = MyTerrainY(Boden,xnew,y,znew)
 PositionEntity pright,xnew,rightheight,znew

 pitchx# = tAuto\Laenge*2 ; need complete length of Auto for x
 pitchy# = (backheight - frontheight); the height dif between the front and rear of Auto
 pitch = ATan2(pitchx,pitchy); atan2 will return the angle from 0,0 to x,y

 rollx# = tAuto\Breite*2
 rolly# = (rightheight - leftheight) ; the height dif between the left and right of Auto
 roll# = ATan2(rollx,rolly); atan2 will return the angle from 0,0 to x,y

 RotateEntity tAuto\Entity, pitch-90,yaw,roll-90 ; rotate Auto with offsets to adjust Atan2's calculation

 th=(frontheight+backheight+leftheight+rightheight)/4; get average of Boden heights for Autos overall height
 
 tAuto\px=x
 tAuto\py=th
 tAuto\pz=z
 PositionEntity tAuto\Entity,tAuto\px,tAuto\py,tAuto\pz

 ;--------------------------------------------------------------------------------------------------

 If KeyDown(208) And speed>-10 Then speed=speed-0.5
 If KeyDown(200) And speed< 80 Then speed=speed+0.5

 Steigung#=Steigung(pback,pfront)

 speed=speed+Steigung/100

 speed=speed*0.998 ;Reibung

 MoveEntity tAuto\Entity,0,0,speed

 ;ZentralAchse
 PositionEntity pop,EntityX(tAuto\Entity),EntityY(tAuto\Entity),EntityZ(tAuto\Entity) 
 RotateEntity pop,EntityPitch(tAuto\Entity),EntityYaw(tAuto\Entity),EntityRoll(tAuto\Entity)

 PositionEntity camera,EntityX(tAuto\Entity),EntityY(tAuto\Entity),EntityZ(tAuto\Entity) 
 RotateEntity camera,EntityPitch(tAuto\Entity),EntityYaw(tAuto\Entity),EntityRoll(tAuto\Entity)
 MoveEntity camera,0,70,0   ;UP
 MoveEntity camera,0,0,-100 ;BACK
 MoveEntity camera,-60,0,0 ;LEFT
 TurnEntity camera,5,0,0   ;Look a little bit down

 ;--------------------------------------------------------------------------------------------------

 UpdateWorld
 RenderWorld

 Color 255,255,255
 Text 4,4+fonty*0,"Steigung "+R2(Steigung)
 Text 4,4+fonty*1,"Speed "+R2(Speed)
 Text 4,4+fonty*2,"MSG "+msg$

 Flip

 If KeyHit(1) Then Ret=False:Exit

 Forever

 Return Ret

End Function

;##################################################################################################

Function Steigung#(eback,efront)

 ;MR 24.02.2003

 ; - Berg Hoch   , Hill up
 ; + Berg Runter , Hill down

 Local winkel# ;angle in degrees

 Local dx#,dy#,dz# ;delta

 dx#=EntityX(efront)-EntityX(eback)
 dy#=EntityY(efront)-EntityY(eback)
 dz#=EntityZ(efront)-EntityZ(eback)

 Local xz#

 xz#=Sqr(dx*dx+dz*dz)

 winkel#=ATan2(dy#,Abs(xz#))

 Return winkel#

End Function

;##################################################################################################

Function R2#(x#)

 ;MR 25.02.2003

 ;Rundet eine Fließkomma Zahl auf zwei Nachkommastellen um sie im Display anzuzeigen

 Return Int(x*100.0)/100.0

End Function

;##################################################################################################


Function MakeStreet()

 Local m,s,v1,v2,v3,v4
 Local x,y,z

 x=256
 z=256

 m=CreateMesh()

 ;---------------------------------------

 s=CreateSurface(m,br1)

 ;Links Oben
 v1=AddVertex(s,-x,0, z,0,0)
 v2=AddVertex(s, 0,0, z,1,0)
 v3=AddVertex(s, 0,0, 0,1,1)
 v4=AddVertex(s,-x,0, 0,0,1)

 AddTriangle s,v1,v2,v3
 AddTriangle s,v3,v4,v1

 ;Links unten
 v1=AddVertex(s,-x,0, 0,0,0)
 v2=AddVertex(s, 0,0, 0,1,0)
 v3=AddVertex(s, 0,0,-z,1,1)
 v4=AddVertex(s,-x,0,-z,0,1)

 AddTriangle s,v1,v2,v3
 AddTriangle s,v3,v4,v1

 ;---------------------------------------

 s=CreateSurface(m,br2)

 ;Rechts Oben
 v1=AddVertex(s, 0,0, z,0,0)
 v2=AddVertex(s, x,0, z,1,0)
 v3=AddVertex(s, x,0, 0,1,1)
 v4=AddVertex(s, 0,0, 0,0,1)

 AddTriangle s,v1,v2,v3
 AddTriangle s,v3,v4,v1

 ;Rechts unten
 v1=AddVertex(s, 0,0, 0,0,0)
 v2=AddVertex(s, x,0, 0,1,0)
 v3=AddVertex(s, x,0,-z,1,1)
 v4=AddVertex(s, 0,0,-z,0,1)

 AddTriangle s,v1,v2,v3
 AddTriangle s,v3,v4,v1
 
 ;---------------------------------------

 ;Randsteine

 AddMyMeshCubeX m,-x   ,1,z*.8,-x-15,50,-z*.8,0,0,0,brgr,brgr,brgr,brgr,brgr,brgr,1,1,1,1,1,1 ;Links
 AddMyMeshCubeX m, x+15,1,z*.8, x   ,50,-z*.8,0,0,0,brgr,brgr,brgr,brgr,brgr,brgr,1,1,1,1,1,1 ;Rechts

 ;---------------------------------------

 PositionMesh m,0,0,MeshDepth(m)/2 ;vorne anfassen

 ;---------------------------------------

 EntityFX m,16

 EntityPickMode m,2

 Return m

End Function

Function AddMyMeshCubeX(m,x1#,y1#,z1#,x2#,y2#,z2#,cx,cy,cz,br_top,br_bottom,br_left,br_right,br_front,br_back,o_top=1,o_bottom=1,o_left=1,o_right=1,o_front=1,o_back=1)

 ;MR 31.10.2002

 ;Create a Cube centered

 ;m       =Entity Handle 0=Create a new one :-)
 ;x1,x2   =From X1 To X2
 ;cx,cy,cy=Center 
 ;br_     =Brush  Handle
 ;o_      =Optional 1=Create 0=No Create 
 
  Local w#,h#,d#

 ;w#=witdh  (X)
 ;h#=height (Y)
 ;d#=depth  (Z)

  w#=x2#-x1#
  h#=y2#-y1#
  d#=z2#-z1#

  ;--------------------- Center ?

  If cx=1 Then
   x1=x1-w/2.0
   x2=x2-w/2.0
  EndIf

  If cy=1 Then
   y1=y1-h/2.0
   y2=y2-h/2.0
  EndIf

  If cz=1 Then
   z1=z1-d/2.0
   z2=z2-d/2.0
  EndIf

  ;-----------------------------

  If m=0 Then
    m=CreateMesh()
  EndIf

  ;-----------------------------

   ;top face
   If o_top=1 Then
    s=CreateSurface( m , Br_Top)
    AddVertex s,x1,y2,z2,0,1:AddVertex s,x2,y2,z2,0,0
    AddVertex s,x2,y2,z1,1,0:AddVertex s,x1,y2,z1,1,1
    AddTriangle s,0,1,2:AddTriangle s,0,2,3
  EndIf

   ;bottom face   
  If o_bottom=1 Then
    s=CreateSurface( m , Br_Bottom)
    AddVertex s,x1,y1,z1,1,0:AddVertex s,x2,y1,z1,1,1
    AddVertex s,x2,y1,z2,0,1:AddVertex s,x1,y1,z2,0,0
    AddTriangle s,0,1,2:AddTriangle s,0,2,3
  EndIf

   ;left face
  If o_left=1 Then
    s=CreateSurface( m , Br_Left)
    AddVertex s,x1,y2,z2,0,0:AddVertex s,x1,y2,z1,1,0
    AddVertex s,x1,y1,z1,1,1:AddVertex s,x1,y1,z2,0,1
    AddTriangle s,0,1,2:AddTriangle s,0,2,3
  EndIf

   ;right face
  If o_right=1 Then
    s=CreateSurface( m , Br_Right)
    AddVertex s,x2,y2,z1,0,0:AddVertex s,x2,y2,z2,1,0
    AddVertex s,x2,y1,z2,1,1:AddVertex s,x2,y1,z1,0,1
    AddTriangle s,0,1,2:AddTriangle s,0,2,3
  EndIf

   ;front face
  If o_front=1 Then
    s=CreateSurface( m , Br_Front)
    AddVertex s,x1,y2,z1,0,0:AddVertex s,x2,y2,z1,1,0
    AddVertex s,x2,y1,z1,1,1:AddVertex s,x1,y1,z1,0,1
    AddTriangle s,0,1,2:AddTriangle s,0,2,3
  EndIf

   ;back face
  If o_back=1 Then
    s=CreateSurface( m , Br_Back)
    AddVertex s,x2,y2,z2,0,0:AddVertex s,x1,y2,z2,1,0
    AddVertex s,x1,y1,z2,1,1:AddVertex s,x2,y1,z2,0,1
    AddTriangle s,0,1,2:AddTriangle s,0,2,3
  EndIf

  NameEntity m,"STR"

  UpdateNormals m
    
  EntityPickMode m,2 ;Poly

  Return m 

End Function

;#######################################################################################

Function MyTerrainY#(TE,x#,y#,z#,deb=0)

 If TE=0 Then RuntimeError "MyTerrainY TE=0 !"

 Local ty#=y

 ty=TerrainY(TE,x,y,z)

 If deb=True Then msg$="";+R2(x)+" "+R2(y)+" "+R2(z)

 LinePick(x,y+512,z,0,-200000,0)
 If PickedEntity() Then
  ty=PickedY()
  If deb=True Then msg$=msg$+" Name="+EntityName(PickedEntity())
 EndIf

 ;If deb=True Then msg$=msg$+" ty="+R2(ty)

 Return ty

End Function

;#######################################################################################

Flori-D

BeitragFr, Mai 21, 2004 20:29
Antworten mit Zitat
Benutzer-Profile anzeigen
THX.Kann ich gut gebrauchen.
BB is Macht!

Homepage: www.flori-d.de

Neue Antwort erstellen


Übersicht BlitzBasic Blitz3D

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group