Hello i got a problem with my programm and maybe anyone want to help me =)
I got a flat and a sphere on it. I want to rotate the flat, if the sphere is on the flat, the sphere have to move up or down.
I don't know what i am doing wrong with the calculating the way the sphere have to move to be on the flat.
I got a flat and a sphere on it. I want to rotate the flat, if the sphere is on the flat, the sphere have to move up or down.
I don't know what i am doing wrong with the calculating the way the sphere have to move to be on the flat.
;Graphics Graphics3D 800,600,16,2 SetBuffer BackBuffer() ;Collisions Const COL_BALL=1,COL_LAB=2 Collisions COL_BALL,COL_LAB,2,2 ;sphere-to-polygon, sliding collisions ;Frames per Second Global fps=CreateTimer(30) ;Camera camera=CreateCamera() PositionEntity camera,0,50,-40 RotateEntity camera,45,0,0 ;Light light=CreateLight() PositionEntity light,0,50,50 ;Lab lab=CreateCube() Const LAB_LENGTH = 20 ScaleMesh lab,20,3,20 PositionEntity lab,0,0,0 EntityType lab,COL_LAB mx=0 ;Variable from the labarinth my=0 ;Ball ball=CreateSphere() ScaleMesh ball,3,3,3 PositionEntity ball,10,10,0 EntityType ball,COL_BALL ResetEntity ball UpdateWorld RenderWorld ;------------------------------; ; Main ;------------------------------; While Not KeyHit(1) ;Wait for Frames per Second WaitTimer(fps) ;Store Mouse Movement mxs = MouseXSpeed() mys = 0;MouseYSpeed() If MouseDown(1) ;linke maustaste ;calculate alpha If mx-mxs>-20 And mx-mxs<20 alpha=mx-mxs Else If mx-mxs<-20 alpha=-20 Else If mx-mxs>20 alpha=20 End If ;Coordinates of ball ballX = EntityX(ball) ballY = EntityY(ball) ;If lab rotates move ball If mx <> alpha If mx<0 And alpha>0 Then yVerschiebung = (Sin(mx)*ballX) yVerschiebung = yVerschiebung + (Sin(alpha)*ballX)-(ballY) Else If alpha > mx And alpha>0 Then yVerschiebung = (Sin(alpha)*ballX)-(ballY) If yVerschiebung <> 0 yVerschiebung = yVerschiebung End If Else If alpha > mx And alpha<0 Then yVerschiebung = (Sin(alpha)*ballX)-(ballY) End If End If ;move ball If yVerschiebung > 0 Then If EntityX(ball)>0 Then MoveEntity ball,0,yVerschiebung,0 End If End If yVerschiebung = 0 ;X-Axis If mx-mxs>-20 And mx-mxs<20 mx=mx-mxs Else If mx-mxs<-20 mx=-20 Else If mx-mxs>20 mx=20 End If ;Y-Axis If my-mys>-20 And my-mys<20 my=my-mys Else If my-mys<-20 my=-20 Else If my-mys>20 my=20 End If RotateEntity lab,my,0,mx,True ;True = relative to 0,0,0 origin EndIf If MouseDown(2) ;right mouse, reposition ball PositionEntity ball,10,10,0 End If MoveEntity ball,0,-1,0 UpdateWorld ;check collisions etc. RenderWorld ;Render the scene Flip ;Flip Backbuffer Wend ;------------------------------; ; End Main ;------------------------------;