Kollision und Abprallen mittels Collision(N)X/Y/Z
Übersicht

nitroexBetreff: Kollision und Abprallen mittels Collision(N)X/Y/Z |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo erstma!
Folgendes Prob: Ich habe ein Terrain und lasse da eine objekt draufzu fliegen o.ä. Nun möcht ich, dass das Objekt, wenn es mit dem Terrain kollidiert, abprallt, und zwar so: \|/ . Das heisst, ich wollte die Normale mit "CollisionNX/Y/Z" (oder selber mit "CollisionX/Y/Z") ermitteln, und mittels des Aufprallvektors und dessen Winkel in Zusammenhang mit der Normale den neuen Abprallwinkel errechnen. Mein Code: Code: [AUSKLAPPEN] Function aufk() If CountCollisions(k1) Then x#=EntityX(k1) y#=EntityY(k1) z#=EntityZ(k1) kx#=CollisionX(k1,1) ky#=CollisionY(k1,1) kz#=CollisionZ(k1,1) lkv#=Sqr((kx#-x#)^2+(ky#-y#)^2+(kz#-z#)^2) lsv#=Sqr(pt\px#^2+pt\py#^2+pt\pz#^2) If lsv#<>0 Then alpha#=ACos(((kx#*x#+ky#*y#+kz#*z#)/lkv#/lsv#)) Text 0,130,"Alpha: "+alpha# Text 0,140,"lkv,lsv: "+lkv#+","+lsv# End If End If End Function Wann ich das "ACos" da lasse, zeigt er "NaN" (Not a Number), und wenn ich es wegmache, dann wächst das inns unendliche. Kann mir da jemand helfen? Was hab ich falsch gemacht? mfg :: nitroex |
||
![]() |
Markus2 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Code: [AUSKLAPPEN] For i = 1 To CountCollisions(entity) ; Calculate bounce: ; Get the normal of the surface collided with. Nx# = CollisionNX#(entity, i) Ny# = CollisionNY#(entity, i) Nz# = CollisionNZ#(entity, i) ; Compute the dot product of the ball's motion vector and the normal of the surface collided with. VdotN# = xvel#*Nx# + yvel#*Ny# + zvel#*Nz# ; Calculate the normal force. NFx# = -2.0 * Nx# * VdotN# NFy# = -2.0 * Ny# * VdotN# NFz# = -2.0 * Nz# * VdotN# ; Add the normal force to the motion vector. xvel#=(xvel# + NFx#)*bounce# yvel#=(yvel# + NFy#)*bounce# zvel#=(zvel# + NFz#)*bounce# Next Und mal ein eigenständiges Prog. was die Normale anzeigt ![]() Code: [AUSKLAPPEN] ; Blitz3D Collisionsprüfung mit darstellung der CollisionsNormale :-) ; MR 06.10.2003 ;--------------------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() ;--------------------------------- Global camera=CreateCamera() RotateEntity camera,20,0,0 PositionEntity camera,0,10,-10 ;--------------------------------- light=CreateLight() RotateEntity light,45,0,0 ;--------------------------------- sphere=CreateSphere(32) EntityType sphere,1 EntityRadius sphere,1 PositionEntity sphere,0,11,0 EntityColor sphere,0,0,255 NameEntity sphere,"Sphere" ;--------------------------------- cube=CreateCube() EntityType cube,2 EntityColor cube,0,100,0 PositionEntity cube,0,-5,0 ScaleEntity cube,10,10,10 NameEntity cube,"Cube" tex=CreateTexture(64,64) SetBuffer TextureBuffer(tex) Color 255,255,255 Rect 0,0,64,64 Color 128,128,128 Rect 0,0,32,32 Rect 32,32,32,32 SetBuffer BackBuffer() EntityTexture cube,tex ScaleTexture tex,1.0/10.0,1.0/10.0 ;--------------------------------- pyra=CreateCone() EntityType pyra,2 EntityColor pyra,0,255,255 PositionEntity pyra,-5,4,-4 ScaleEntity pyra,2,2,2 NameEntity pyra,"Pyra" ;--------------------------------- cylinder=CreateCylinder(32) EntityType cylinder,2 EntityColor cylinder,255,0,0 PositionEntity cylinder,0,7,0 ScaleEntity cylinder,2,2,2 RotateEntity cylinder,-20,0,10 ;<--- bischen kippen NameEntity cylinder,"Cylinder" ;--------------------------------- Collisions 1,2,2,2 ;Type 1 mit Type 2 , Kugel mit Polygon Test 2 , 2 mit abrutschen ;--------------------------------- While Not KeyDown(1) Local x#,y#,z# x#=0 y#=0 z#=0 If KeyDown(203)=1 Then x#=-0.1 If KeyDown(205)=1 Then x#=0.1 If KeyDown(208)=1 Then z#=-0.1 If KeyDown(200)=1 Then z#=0.1 MoveEntity sphere,x#,-0.1,z# ;runter fallen UpdateWorld ;Collisions erkennung RenderWorld ;3D Darstellung col=CountCollisions(sphere) Color 255,255,255 Text 0,0,"Kollision(en):" For i=1 To col ;If cylinder=CollisionEntity(sphere,i) Then ;wenn man nur den Cylinder testen will p=i ;p=1 Text 000,p*20,"Mit '"+EntityName(CollisionEntity(sphere,i))+ "'" Local nx#,ny#,nz# nx#=CollisionNX(sphere,i) ;Normale ny#=CollisionNY(sphere,i) nz#=CollisionNZ(sphere,i) x#=CollisionX(sphere,i) ;Wo die Collision statt findet y#=CollisionY(sphere,i) z#=CollisionZ(sphere,i) NormalNew x,y,z,nx,ny,nz ;merken um sie später alle anzuzeigen Text 150,p*20,"NX="+nx Text 300,p*20,"NY="+ny Text 450,p*20,"NZ="+nz ;EndIf Next NormalShowAll ;jetzt will ich sie alle sehen ! (nach Renderworld) Flip Wend End ;################################################################################################### .Normals Type NormalType Field x# Field y# Field z# Field nx# Field ny# Field nz# End Type Global Normal.NormalType ;################################################################################################### Function NormalNew(x#,y#,z#,nx#,ny#,nz#) ;Normale merken ;------------------------------------- ;begrenzen auf xx , wenn mehr dann die ersten löschen Local c For Normal.NormalType =Each NormalType c=c+1 If c=50 Then Delete First NormalType Exit EndIf Next ;------------------------------------- Normal.NormalType =New NormalType Normal\x=x Normal\y=y Normal\z=z Normal\nx=nx Normal\ny=ny Normal\nz=nz End Function ;################################################################################################### Function NormalShowAll() ;Malt alle Normalen auf den Screen For Normal.NormalType =Each NormalType NormalShow Normal,3 Next End Function ;################################################################################################### Function NormalShow(N.NormalType,laenge#) ;MR 06.10.2003 ;camera muß Global sein für diese Function und das Handle der Camera ;Malt die Normale auf den Screen Local x1,y1 Local x2,y2 CameraProject camera,n\x,n\y,n\z x1=ProjectedX() y1=ProjectedY() If ProjectedZ()=0 Then Return CameraProject camera,n\x+n\nx*laenge,n\y+n\ny*laenge,n\z+n\nz*laenge x2=ProjectedX() y2=ProjectedY() If ProjectedZ()=0 Then Return mLineClip x1,y1,x2,y2 End Function ;################################################################################################### Function mLineClip(x1,y1,x2,y2) ;Wegen CameraProjected XYZ zu XY nur Linien malen die auch im Screen sind ! If x1=>0 And y1=>0 And x2=>0 And y2=>0 Then If x1<GraphicsWidth() And y1<GraphicsHeight() And x2<GraphicsWidth() And y2<GraphicsHeight() Then Color 255,255,0 Line x1,y1,x2,y2 Color 0,0,0 Rect x1-2,y1-2,4,4 EndIf EndIf End Function ;################################################################################################### |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group