Stones Gun
Posted: Fri Nov 01, 2013 3:47 pm
i have posted here http://www.purebasic.fr/english/viewtop ... 40#p429603 for the MP3D forum what appears as a stones thrower which have the appearance of water emanating from a nozzle, it appears that the behavior of the 3D engine pushing the cubes, but this is not the only reason it appears that the cubes influence each other so they come out in a stream. if you try to push one cube only it will be a poor push.
so i want to try this in PB 3D Ogre, the same as above , pushing only one cube gives the one cube a poor power. but when we make many cubes it affects each other sequentially so it is emanating strongly
note that near the end of the 1000 stones which are shared between the Gun and the enemy artilleries your system will may be be slow , depends on your pc
also note that since we want the Guns tilted 45 degree so we should also rotate the cubic stones 45 deg also. but still i can't get a one clean flow of the cubic stones.
also note that positioning of the cubic stones are critical to direct the stones . also the stone size dictate how much powerfull the stream is
Edit:
this is using balls instead of the cubes for the stones, note that the green gun throw exact stream of balls (it is a scaled cube) while the blue gun throw semi chaotic balls (note that it is a hollow cylinder) . the power supplied to the balls by using the 3D engine reflex to the objects when they are in the same place and time which are prohibited. imagine this as a gas pressure.

when you feel the game begins to die press F to free ball entities and recharge again. the blue hollow gun needs more design while the left green gun are good. a future version will be a portable artillery in which we can freely change the gun angle. don't forget that the official example FPSFirstPerson.pb in C:\PureBasic\Examples\3D\Demos have a great gun which utilize the power from ApplyEntityImpulse(Shoot, ...), my example utilize the power from illegal action in pressing a 6000 balls in the same place or almost so utilizing how the 3d engine behaves in this situation
so i want to try this in PB 3D Ogre, the same as above , pushing only one cube gives the one cube a poor power. but when we make many cubes it affects each other sequentially so it is emanating strongly
note that near the end of the 1000 stones which are shared between the Gun and the enemy artilleries your system will may be be slow , depends on your pc
also note that since we want the Guns tilted 45 degree so we should also rotate the cubic stones 45 deg also. but still i can't get a one clean flow of the cubic stones.
also note that positioning of the cubic stones are critical to direct the stones . also the stone size dictate how much powerfull the stream is
Code: Select all
Declare dropStone(stn.l)
Declare dropStone2(stn.l)
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "press Space / Z to throw stones", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0)-5, 0, 0, 0)
#stone = 5
Global Dim stone(1000)
Global stn, stn2
;-Texture
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures/",#PB_3DArchive_FileSystem)
LoadTexture(0,"wood.jpg")
;-Material
CreateMaterial(1,TextureID(0))
SetMaterialColor(1, #PB_Material_AmbientColor, RGB(100,100,100))
CreateMaterial(2,TextureID(0))
SetMaterialColor(2, #PB_Material_AmbientColor, $FFFF00)
MaterialCullingMode(2, #PB_Material_NoCulling )
;- Entities
CreatePlane(1,30,30,20,20,1,1)
plane = CreateEntity(#PB_Any, MeshID(1), MaterialID(1))
EntityPhysicBody(plane, #PB_Entity_StaticBody)
CreateCube(2, 1)
CreateCylinder(3, 1, 4 , 0, 0, 0)
Gun = CreateEntity(#PB_Any,MeshID(2), MaterialID(2))
ScaleEntity(Gun,2,1,1)
MoveEntity(Gun,-7,4,0)
RotateEntity(Gun, 0, 0,-135)
EntityPhysicBody(Gun,#PB_Entity_StaticBody ,100)
enemy = CreateEntity(#PB_Any,MeshID(3), MaterialID(2))
;ScaleEntity(Gun,2,1,1)
MoveEntity(enemy,6,4,0)
RotateEntity(enemy, 0, 45,45)
EntityPhysicBody(enemy,#PB_Entity_StaticBody ,10)
;- Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,-2,8,18)
CameraLookAt(0,-2,5,0)
;-Light
AmbientColor($666666)
CreateLight(0,RGB(160,160,255),200,400,200)
CreateCube(#stone, 0.7)
For i = 1 To 1000
stone(i) = CreateEntity(#PB_Any, MeshID(#stone),#PB_Material_None)
Next
;- Main loop
Repeat
Event = WindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space)
;If KeyboardReleased(#PB_Key_Space)
stn+1
If stn > 1000: stn=1: EndIf
dropStone(stn)
EndIf
If KeyboardPushed(#PB_Key_Z)
;If KeyboardReleased(#PB_Key_Space)
stn+1
If stn > 1000: stn=1: EndIf
dropStone2(stn)
EndIf
; Render
RenderWorld()
FlipBuffers()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow
End
Procedure dropStone(stn.l)
MoveEntity(stone(stn), -6.3,5,0)
RotateEntity(stone(stn), 0, 0,-135)
EntityPhysicBody(stone(stn),#PB_Entity_BoxBody,1)
EndProcedure
Procedure dropStone2(stn.l)
MoveEntity(stone(stn), 6,4,0)
RotateEntity(stone(stn), 0, 0,45)
EntityPhysicBody(stone(stn),#PB_Entity_BoxBody,1)
EndProcedurethis is using balls instead of the cubes for the stones, note that the green gun throw exact stream of balls (it is a scaled cube) while the blue gun throw semi chaotic balls (note that it is a hollow cylinder) . the power supplied to the balls by using the 3D engine reflex to the objects when they are in the same place and time which are prohibited. imagine this as a gas pressure.

when you feel the game begins to die press F to free ball entities and recharge again. the blue hollow gun needs more design while the left green gun are good. a future version will be a portable artillery in which we can freely change the gun angle. don't forget that the official example FPSFirstPerson.pb in C:\PureBasic\Examples\3D\Demos have a great gun which utilize the power from ApplyEntityImpulse(Shoot, ...), my example utilize the power from illegal action in pressing a 6000 balls in the same place or almost so utilizing how the 3d engine behaves in this situation
Code: Select all
Declare dropStone(stoneNum.l)
Declare dropStone2(stoneNum.l)
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "press Space / Z to throw stones .... F ..to free stones entities and Recharge", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0)-5, 0, 0, 0)
#stone = 5
Global Dim stone(6000)
Global stoneNum
;-Texture
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures/",#PB_3DArchive_FileSystem)
LoadTexture(0,"wood.jpg")
LoadTexture(1,"clouds.jpg")
;-Material
CreateMaterial(1,TextureID(0))
SetMaterialColor(1, #PB_Material_AmbientColor, RGB(100,100,100))
CreateMaterial(2,TextureID(0))
SetMaterialColor(2, #PB_Material_AmbientColor, $FFFF00)
MaterialCullingMode(2, #PB_Material_NoCulling )
CreateMaterial(3,TextureID(1))
SetMaterialColor(3, #PB_Material_AmbientColor, RGB(255,255,255))
;- Entities
CreatePlane(1,30,30,20,20,1,1)
plane = CreateEntity(#PB_Any, MeshID(1), MaterialID(1))
EntityPhysicBody(plane, #PB_Entity_StaticBody)
CreateCube(2, 1)
CreateCylinder(3, 0.7, 6 , 0, 0, 0)
GunRed = CreateEntity(#PB_Any,MeshID(2), MaterialID(2))
ScaleEntity(GunRed,2,1,1)
MoveEntity(GunRed,-7,4,0)
RotateEntity(GunRed, 0, 0,-135)
EntityPhysicBody(GunRed,#PB_Entity_StaticBody ,100)
GunBlue = CreateEntity(#PB_Any,MeshID(3), MaterialID(3))
;ScaleEntity(Gun,2,1,1)
MoveEntity(GunBlue,6,4,0)
RotateEntity(GunBlue, 0, 45,45)
EntityPhysicBody(GunBlue,#PB_Entity_StaticBody ,100)
;- Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,-2,8,18)
CameraLookAt(0,-2,5,0)
;-Light
AmbientColor($666666)
CreateLight(0,RGB(160,160,255),200,400,200)
;CreateCube(#stone, 0.5)
CreateSphere(#stone, 0.4 )
For i = 0 To 6000
stone(i) = CreateEntity(#PB_Any, MeshID(#stone),#PB_Material_None)
Next
;- Main loop
Repeat
Event = WindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space)
;If KeyboardReleased(#PB_Key_Space)
stoneNum+1
If stoneNum > 6000: stoneNum=0: EndIf
dropStone(stoneNum)
EndIf
If KeyboardPushed(#PB_Key_Z)
;If KeyboardReleased(#PB_Key_Space)
stoneNum+1
If stoneNum > 6000: stoneNum=0: EndIf
dropStone2(stoneNum)
EndIf
If KeyboardPushed(#PB_Key_F) ; free the stone entities and recreate them again
For i=0 To 6000
FreeEntity(stone(i))
stoneNum=0 : temp = 0
Next
For i = 0 To 6000
stone(i) = CreateEntity(#PB_Any, MeshID(#stone),#PB_Material_None)
Next
EndIf
;Render
RenderWorld()
FlipBuffers()
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
temp + 1
If temp > 200 ; free every 201 stone entities thrown
temp = 0
For i=1 To temp
FreeEntity(stone(stoneNum - i))
Next
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow
End
Procedure dropStone(stoneNum.l)
MoveEntity(stone(stoneNum), -6.4,4.9,0)
RotateEntity(stone(stoneNum), 0, 0,-135)
EntityPhysicBody(stone(stoneNum),#PB_Entity_BoxBody,1)
EndProcedure
Procedure dropStone2(stoneNum.l)
SetEntityMaterial(stone(stoneNum), MaterialID(2))
MoveEntity(stone(stoneNum), 4.7,5.2,0)
EntityPhysicBody(stone(stoneNum),#PB_Entity_BoxBody,1)
EndProcedure

