It is currently Mon Sep 23, 2019 2:28 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: example GenericJoint - car control
PostPosted: Wed Mar 06, 2019 10:18 am 
Offline
User
User

Joined: Thu Jul 09, 2015 9:07 am
Posts: 74
a small example of car control via GenericJoint and ApplyEntityTorque

[EDIT] I added "WindowEvent()" in main loop

Code:
; GenericJoint - exemple voiture - pf Shadoko - 2018

Procedure matiere(num,dx,dy,c1,c2, brillance=$888888)
  CreateTexture(num,dx,dy)
  StartDrawing(TextureOutput(num))
  DrawingMode(#PB_2DDrawing_AllChannels )
  Box(0,0,dx,dy,c2)
  Box(2,2,dx-4,dy-4,c1)
  StopDrawing()
  CreateMaterial(num, TextureID(num))
  If brillance:SetMaterialColor(num, #PB_Material_SpecularColor, brillance):MaterialShininess(num, 20):EndIf
EndProcedure

EnableExplicit
Define.f angle,sens,dsens,h
Define i,ii,j,c,l,dis=0,vdis=2<<dis*1,ex,ey,ombre

InitEngine3D():InitSprite():InitKeyboard():InitMouse()
OpenWindow(0, 0, 0, 0,0, " Test GenericJoint  - curseur + F2(camera) + F3(ombres)",#PB_Window_Maximize)
ex=WindowWidth (0,#PB_Window_InnerCoordinate)
ey=WindowHeight(0,#PB_Window_InnerCoordinate)
OpenWindowedScreen(WindowID(0), 0, 0, ex, ey, 0, 0, 0)

CreateLight(0,$888888, 5000, 3000, 2000):SetLightColor(0, #PB_Light_SpecularColor, $ffffff)
AmbientColor($777777)

CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,10,-20)
CameraBackColor(0,$888888)

;WorldDebug(#PB_World_DebugBody)
WorldShadows(#PB_Shadow_Additive)

matiere(0,256,256,$444444,$111111)
matiere(1,256,256,$884444,$441111)
matiere(2,256,256,$ffff00,$444400)
matiere(3,256,256,$ffffff,$444444)
matiere(4,256,256,$4444ff,$4444ff)
matiere(5,256,256,$44ffff,$00aaaa)
matiere(10,256,256,$888888,$222222)

;---------------------piste
CreatePlane(0,200,200,1,1,200,200)
CreateEntity(100,MeshID(0),MaterialID(10),0,0,0):CreateEntityBody(100,#PB_Entity_StaticBody,1,0,1)
CreateCone(0,4,2,32,4)
For i=200 To 219:CreateEntity(i,MeshID(0),MaterialID(4),Random(100)-50,1,Random(100)-50):CreateEntityBody(i,#PB_Entity_StaticBody,1,0,1):Next
CreateCube(0,4)
For i=300 To 339:CreateEntity(i,MeshID(0),MaterialID(1),Random(100)-50,-1,Random(100)-50):RotateEntity(i,25,Random(360),0):CreateEntityBody(i,#PB_Entity_StaticBody,1,0,1):Next
CreateCube(0,0.1):TransformMesh(0,0,0.025,0,1,0.5,50,0,0,0):UpdateMeshBoundingBox(0)
For i=400 To 439:CreateEntity(i,MeshID(0),MaterialID(2),Random(100)-50,0,Random(100)-50):RotateEntity(i,0,Random(360),0):CreateEntityBody(i,#PB_Entity_StaticBody,1,0,1):Next

;--------------------- voiture
h=2
CreateCube(0,2):TransformMesh(0,0,0,0,0.4,0.2,0.8,0,0,0):UpdateMeshBoundingBox(0)
CreateEntity(0, MeshID(0), MaterialID(5),0,h,0):CreateEntityBody(0, #PB_Entity_BoxBody ,4, 0.0,0.3):SetEntityCollisionFilter(0, 1,2)
SetEntityAttribute(0,#PB_Entity_LinearSleeping,0)

;---------------------roues
CreateCylinder(2, 0.3, 0.3)
For j=-1 To 1 Step 2:For i=-1 To 1 Step 2:c+1
    CreateEntity(c, MeshID(2), MaterialID(0),0.6*i, -0.2+h, -0.8*j):CreateEntityBody(c, #PB_Entity_CylinderBody, 1, 0,0.7):SetEntityCollisionFilter(c, 1,2)
    RotateEntity(c,0,0,90)
    GenericJoint(c, EntityID(0),0.6*i, -0.2, -0.8*j, EntityID(c), 0, 0, 0)
    SetJointAttribute(c, #PB_Joint_EnableSpring,1,1)
    SetJointAttribute(c, #PB_Joint_Damping,0.005,1)
    SetJointAttribute(c, #PB_Joint_Stiffness,200,1)
    SetJointAttribute(c, #PB_Joint_NoLimit, 0, 3)
Next :Next

CreateNode(0,0,0.0,-1):AttachEntityObject(0,"",NodeID(0))
CreateNode(1,0,0.1,0) :AttachEntityObject(0,"",NodeID(1))

Repeat
  While WindowEvent():Wend
  ExamineMouse()
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_F2):dis=(dis+1)%3:vdis=2<<dis*1:EndIf
  If KeyboardReleased(#PB_Key_F3):ombre=1-ombre:If ombre:WorldShadows(#PB_Shadow_Additive):Else:WorldShadows(#PB_Shadow_None):EndIf:EndIf
 
  sens=(GetEntityAttribute(1,#PB_Entity_AngularVelocity)+GetEntityAttribute(2,#PB_Entity_AngularVelocity))/2
  angle+(Bool(KeyboardPushed(#PB_Key_Left))-Bool(KeyboardPushed(#PB_Key_Right)))*-0.02:angle/(1+sens*0.002)
  dsens=(Bool(KeyboardPushed(#PB_Key_Up))-Bool(KeyboardPushed(#PB_Key_Down))) * 100
  SetJointAttribute(1,#PB_Joint_Position,angle,4)
  SetJointAttribute(2,#PB_Joint_Position,angle,4)
  For i=1 To 4:ApplyEntityTorque(i,0,dsens/50,0,#PB_Local):Next
 
  CameraFollow(0, NodeID(1), -180,NodeY(0)+vdis, 2*vdis, 0.1, 0.1)
 
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)


Last edited by pf shadoko on Wed Mar 20, 2019 3:56 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Wed Mar 06, 2019 11:54 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2213
Location: Singapore
Marvellous!

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Mon Mar 11, 2019 8:45 am 
Offline
Addict
Addict
User avatar

Joined: Wed Apr 30, 2003 8:15 am
Posts: 983
Location: Germany
I wonder, where's the code hidden?! ;-)
Great example! :-D

_________________
"Daddy, I'll run faster, then it is not so far..."


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Mon Mar 18, 2019 9:49 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13614
Location: France
Neat !


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Tue Mar 19, 2019 10:07 am 
Offline
User
User

Joined: Mon Jul 17, 2017 7:22 am
Posts: 59
Location: Cotswolds England
I don't know if anyone can help but this type of code, the 3D stuff is a complete mystery to me. Maybe because I'm from the database systems brigade?

In the past I have looked through the demos that come with PureB and they just fall over. It didn't particularly bother me as from experience many demos and examples issued with a language fall over. (In fact it seems to be custom & practice with Microsoft!) So I just presumed they didn't work. Then with this example, which everyone else finds to be brilliant I have the same result. So it must be me! :cry: The demo programs I tried are: Carphysics, Character, PinBall and Tank.

They all end without doing anything and all end with the fatal error message box “The debugged executable quit unexpectedly” which isn't particularly helpful.
This example from pf shadoko opens a blank screen and crashes out in just the same way. Can anyone point me in the right direction and tell what simple step I haven't taken?

_________________
If it's falling over......just remember the computer is never wrong!


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Tue Mar 19, 2019 11:52 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 775
Location: Denmark
@C87
A couple of suggestions:
Install DirectX 9.0c
https://www.microsoft.com/en-us/downloa ... x?id=34429

You could also try to run it with 'OpenGL' as subsystem.

@pf_Shadoko
Yes..neat indeed.

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 7/10, Intel 6800K, Gtx 970, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Tue Mar 19, 2019 2:40 pm 
Offline
User
User

Joined: Mon Jul 17, 2017 7:22 am
Posts: 59
Location: Cotswolds England
@DK_PETER
Thanks for that, I'll need to look into how they work. Maybe the OpenGL of which I've now seen in a few examples. The ActiveXv9 I'm not too keen on installing as MS have v11.3 and/or 12 for Win10. I may have ActiveX9.0 on a WinXP pc, so I can try it there 1st.

It's always the case, something that looks trivial ends up taking hours and hours :lol:

Cheers anyway, C87

_________________
If it's falling over......just remember the computer is never wrong!


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Tue Mar 19, 2019 4:52 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
Very nice indeed!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Tue Mar 19, 2019 5:09 pm 
Offline
User
User

Joined: Thu Jul 09, 2015 9:07 am
Posts: 74
for those who have a crash: try disabling shadows
comment line 31 (WorldShadows(#PB_Shadow_Additive))


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Tue Mar 19, 2019 5:29 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1671
Location: Uttoxeter, UK
@pf shadoko,
I'm using Windows 10 with PureBasic 5.70LTS

I just got a white blank screen which eventually crashed.
I tried 'commenting out' line 31: got a screen showing a vehicle on a terrain. This crashed when pressing a key.

I think something must be missing rather than a bug in your code, any ideas?

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Tue Mar 19, 2019 7:44 pm 
Offline
User
User

Joined: Thu Jul 09, 2015 9:07 am
Posts: 74
try inserting :
WindowEvent()
(line 73, after 'repeat')


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Wed Mar 20, 2019 12:08 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13614
Location: France
Ho yeah, you need to flush the event in windowed mode, even if you don't use them:

Code:
While WindowEvent() : Wend


In the main repeat loop. In fullscreen mode, it's done automatically.


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Wed Mar 20, 2019 2:00 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
davido wrote:
@pf shadoko,
I'm using Windows 10 with PureBasic 5.70LTS

I just got a white blank screen which eventually crashed.

Same here on my notebook, even after inserting the code for flushing events, as Fred wrote. :-(

Yesterday, on a different computer (also on Windows 10), the code worked fine.

Is an advanced graphics card required, or any special setting on the PC regarding 3D processing?

//edit:
In another thread, Fred wrote:
You can try with 'opengl' as subsystem

That fixed the problem here, thank you!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Wed Mar 20, 2019 3:01 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
I could make it work on Window 10 by disabling ;WorldShadows(#PB_Shadow_Additive). It makes renderWorld() hang or crash. I did not try other arguments.
With opengl it's extremely slow/laggy. I'm not sure about my system. dxdiag says direct x 12 and I have read that Windows comes with opengl. I have nvidia drivers installed for the card.
Here is my debug code, printing most function call results. All non-zero.
Code:
; GenericJoint - exemple voiture - pf Shadoko - 2018

OpenConsole()
Procedure deb(i.i)
  PrintN(Str(i))
EndProcedure
Procedure debs(s.s)
  PrintN(s)
EndProcedure

Procedure matiere(num,dx,dy,c1,c2, brillance=$888888)
  deb(CreateTexture(num,dx,dy))
  deb(StartDrawing(TextureOutput(num)))
  DrawingMode(#PB_2DDrawing_AllChannels )
  Box(0,0,dx,dy,c2)
  Box(2,2,dx-4,dy-4,c1)
  StopDrawing()
  CreateMaterial(num, TextureID(num))
  If brillance
    SetMaterialColor(num, #PB_Material_SpecularColor, brillance)
    MaterialShininess(num, 20)
  EndIf
EndProcedure

EnableExplicit
Define.f angle,sens,dsens,h
Define i,ii,j,c,l,dis=0,vdis=2<<dis*1,ex,ey,ombre

deb(InitEngine3D())
deb(InitSprite())
deb(InitKeyboard())
deb(InitMouse())
deb(OpenWindow(0, 0, 0, 0,0, " Test GenericJoint  - curseur + F2(camera) + F3(ombres)",#PB_Window_Maximize))
ex=WindowWidth (0,#PB_Window_InnerCoordinate)
ey=WindowHeight(0,#PB_Window_InnerCoordinate)
deb(OpenWindowedScreen(WindowID(0), 0, 0, ex, ey, 0, 0, 0))

deb(CreateLight(0,$888888, 5000, 3000, 2000))
SetLightColor(0, #PB_Light_SpecularColor, $ffffff)
AmbientColor($777777)

deb(CreateCamera(0, 0, 0, 100, 100))
MoveCamera(0,0,10,-20)
CameraBackColor(0,$888888)

;WorldDebug(#PB_World_DebugBody)
;WorldShadows(#PB_Shadow_Additive)

matiere(0,256,256,$444444,$111111)
matiere(1,256,256,$884444,$441111)
matiere(2,256,256,$ffff00,$444400)
matiere(3,256,256,$ffffff,$444444)
matiere(4,256,256,$4444ff,$4444ff)
matiere(5,256,256,$44ffff,$00aaaa)
matiere(10,256,256,$888888,$222222)

;---------------------piste
deb(CreatePlane(0,200,200,1,1,200,200))
deb(CreateEntity(100,MeshID(0),MaterialID(10),0,0,0))
CreateEntityBody(100,#PB_Entity_StaticBody,1,0,1)
deb(CreateCone(0,4,2,32,4))
For i=200 To 219
  deb(CreateEntity(i,MeshID(0),MaterialID(4),Random(100)-50,1,Random(100)-50))
  CreateEntityBody(i,#PB_Entity_StaticBody,1,0,1)
Next
deb(CreateCube(0,4))
For i=300 To 339
  deb(CreateEntity(i,MeshID(0),MaterialID(1),Random(100)-50,-1,Random(100)-50))
  RotateEntity(i,25,Random(360),0)
  CreateEntityBody(i,#PB_Entity_StaticBody,1,0,1)
Next
deb(CreateCube(0,0.1))
TransformMesh(0,0,0.025,0,1,0.5,50,0,0,0)
UpdateMeshBoundingBox(0)
For i=400 To 439
  deb(CreateEntity(i,MeshID(0),MaterialID(2),Random(100)-50,0,Random(100)-50))
  RotateEntity(i,0,Random(360),0)
  CreateEntityBody(i,#PB_Entity_StaticBody,1,0,1)
Next

;--------------------- voiture
h=2
deb(CreateCube(0,2))
TransformMesh(0,0,0,0,0.4,0.2,0.8,0,0,0)
UpdateMeshBoundingBox(0)
deb(CreateEntity(0, MeshID(0), MaterialID(5),0,h,0))
CreateEntityBody(0, #PB_Entity_BoxBody ,4, 0.0,0.3)
SetEntityCollisionFilter(0, 1,2)
SetEntityAttribute(0,#PB_Entity_LinearSleeping,0)

;---------------------roues
deb(CreateCylinder(2, 0.3, 0.3))
For j=-1 To 1 Step 2
  For i=-1 To 1 Step 2:c+1
    deb(CreateEntity(c, MeshID(2), MaterialID(0),0.6*i, -0.2+h, -0.8*j))
    CreateEntityBody(c, #PB_Entity_CylinderBody, 1, 0,0.7)
    SetEntityCollisionFilter(c, 1,2)
    RotateEntity(c,0,0,90)
    deb(GenericJoint(c, EntityID(0),0.6*i, -0.2, -0.8*j, EntityID(c), 0, 0, 0))
    SetJointAttribute(c, #PB_Joint_EnableSpring,1,1)
    SetJointAttribute(c, #PB_Joint_Damping,0.005,1)
    SetJointAttribute(c, #PB_Joint_Stiffness,200,1)
    SetJointAttribute(c, #PB_Joint_NoLimit, 0, 3)
  Next
Next

deb(CreateNode(0,0,0.0,-1))
AttachEntityObject(0,"",NodeID(0))
deb(CreateNode(1,0,0.1,0))
AttachEntityObject(0,"",NodeID(1))

;End

Repeat
  debs("loop")
  While WindowEvent() : Wend
  Delay(1)
  ExamineMouse()
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_F2):dis=(dis+1)%3:vdis=2<<dis*1:EndIf
  If KeyboardReleased(#PB_Key_F3):ombre=1-ombre:If ombre:WorldShadows(#PB_Shadow_Additive):Else:WorldShadows(#PB_Shadow_None):EndIf:EndIf
 
  debs("loop1")
  sens=(GetEntityAttribute(1,#PB_Entity_AngularVelocity)+GetEntityAttribute(2,#PB_Entity_AngularVelocity))/2
  debs("loop2")
  angle+(Bool(KeyboardPushed(#PB_Key_Left))-Bool(KeyboardPushed(#PB_Key_Right)))*-0.02:angle/(1+sens*0.002)
  debs("loop3")
  dsens=(Bool(KeyboardPushed(#PB_Key_Up))-Bool(KeyboardPushed(#PB_Key_Down))) * 100
  debs("loop4")
  SetJointAttribute(1,#PB_Joint_Position,angle,4)
  debs("loop5")
  SetJointAttribute(2,#PB_Joint_Position,angle,4)
  debs("loop6")
  For i=1 To 4
    ApplyEntityTorque(i,0,dsens/50,0,#PB_Local)
  Next
  debs("loop7")
 
  CameraFollow(0, NodeID(1), -180,NodeY(0)+vdis, 2*vdis, 0.1, 0.1)
  debs("loop8")
 
  RenderWorld()
  debs("loop9")
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)


Top
 Profile  
Reply with quote  
 Post subject: Re: example GenericJoint - car control
PostPosted: Wed Mar 20, 2019 3:59 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
#NULL wrote:
I could make it work on Window 10 by disabling ;WorldShadows(#PB_Shadow_Additive).

Works here on Windows 10 with and without OpenGL.
There are rather wide grey margins at the right and at the bottom of the window. However, they were already there in the original version. :-)

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye