torch demo with AttachEntityObject()

Everything related to 3D programming
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

torch demo with AttachEntityObject()

Post by applePi »

look the bug report here:
http://purebasic.fr/english/viewtopic.p ... tityobject
now it works in PB 5.31 beta 1
here is the Statue holding a torch.
in the first example the torch attached to the Statue, the Statue is rotated and so the torch will follow it automatically. in the second example the camera is what is rotated giving more dramatic scene, but here the Statue are not rotating , also the torch are not rotating and not attached to the Statue
in the first example it seems if the torch are affected by the wind while rotating
adapted from the book: PureBasic - A Beginner's Guide" http://purebasic.fr/english/viewtopic.php?f=14&t=37059
to download the book go to http://web.archive.org and write the book zip file address and choose the year 2012

download the Statue and all the related files from here: click on the smaller bottom download icon and not on the big one:
http://www.2shared.com/file/BGxRitsX/Statue.html

demo 1 : needs the files from the above link + PB 5.31 B1

Code: Select all

Enumeration
	#MESH
	#TEXTURE
	#MATERIAL
	#ENTITY
	#CAMERA
	#LIGHT_ONE
	#LIGHT_TWO
	#PARTICLE
EndEnumeration

Global Quit.b = #False

InitEngine3D()
  
  Add3DArchive("Data\", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
    
  Parse3DScripts()
  
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)


OpenWindow(0, 0, 0, DesktopW, DesktopH, "Statue is rotated, the torch are attached to the Statue ")
  OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
     
CreateEntity(#ENTITY, LoadMesh(#MESH, "Statue.mesh"), #PB_Material_None)

LoadTexture(#TEXTURE, "Flame.png")
	CreateMaterial(#MATERIAL, TextureID(#TEXTURE))
	DisableMaterialLighting(#MATERIAL, 1)
	MaterialBlendingMode(#MATERIAL, #PB_Material_Add)

CreateParticleEmitter(#PARTICLE, 2, 2, 0,#PB_Particle_Point,12.9, 69, 15.7)
	ParticleSize(#PARTICLE, 5, 5)
	ParticleMaterial(#PARTICLE, MaterialID(#MATERIAL))
	ParticleEmissionRate(#PARTICLE, 50)
	ParticleTimeToLive(#PARTICLE, 0.25, 0.25)
	ParticleColorRange(#PARTICLE, RGB(255, 0, 0), RGB(255, 200, 0))
	ParticleVelocity(#PARTICLE, 1, 10)

CreateLight(#LIGHT_ONE, RGB(255,255,255))
CreateLight(#LIGHT_TWO, RGB(255, 200, 0), 12.9, 72, 15.7)
CreateCamera(#CAMERA, 0, 0, 100, 100)
MoveCamera(#camera, 0,80,100)

AttachEntityObject(#ENTITY, "", ParticleEmitterID(#PARTICLE)) 


;Main loop
Repeat
  event = WindowEvent()
  
	Angle.f + 0.5
	PosX.f = 75 * Sin(Radian(Angle))
	PosY.f = (50 * Sin(Radian(Angle / 2))) + 65
	PosZ.f = 75 * Cos(Radian(Angle))
	MoveLight(#LIGHT_ONE, PosX, PosY + 100, PosZ)
	SetLightColor(#LIGHT_TWO, #PB_Light_SpecularColor, RGB(255, Random(200), 0))
	RotateEntity(#ENTITY,0,0.5,0,#PB_Relative)
	CameraLookAt(#CAMERA, 0, 60, 0)
	RenderWorld()
	FlipBuffers()

	ExamineKeyboard()
	If KeyboardReleased(#PB_Key_Escape)
		Quit = #True
	EndIf
Until Quit = #True Or event = #PB_Event_CloseWindow
End
demo 2: needs the files from the above link

Code: Select all

Enumeration
	#MESH
	#TEXTURE
	#MATERIAL
	#ENTITY
	#CAMERA
	#LIGHT_ONE
	#LIGHT_TWO
	#PARTICLE
EndEnumeration

Global Quit.b = #False


InitEngine3D()
  
  Add3DArchive("Data\", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
    
  Parse3DScripts()
  
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)


OpenWindow(0, 0, 0, DesktopW, DesktopH, "the camera is rotated according to a formula, the Statue & torch are fixed ")
  OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
     
CreateEntity(#ENTITY, LoadMesh(#MESH, "Statue.mesh"), #PB_Material_None)

LoadTexture(#TEXTURE, "Flame.png")
	CreateMaterial(#MATERIAL, TextureID(#TEXTURE))
	DisableMaterialLighting(#MATERIAL, 1)
	MaterialBlendingMode(#MATERIAL, #PB_Material_Add)

CreateParticleEmitter(#PARTICLE, 2, 2, 0,#PB_Particle_Point,12.9, 69, 15.7)
	ParticleSize(#PARTICLE, 5, 5)
	ParticleMaterial(#PARTICLE, MaterialID(#MATERIAL))
	ParticleEmissionRate(#PARTICLE, 50)
	ParticleTimeToLive(#PARTICLE, 0.25, 0.25)
	ParticleColorRange(#PARTICLE, RGB(255, 0, 0), RGB(255, 200, 0))
	ParticleVelocity(#PARTICLE, 1, 10)

CreateLight(#LIGHT_ONE, RGB(255,255,255))
CreateLight(#LIGHT_TWO, RGB(255, 200, 0), 12.9, 72, 15.7)
CreateCamera(#CAMERA, 0, 0, 100, 100)

;Main loop
Repeat
  event = WindowEvent()
  
	Angle.f + 0.5
	PosX.f = 75 * Sin(Radian(Angle))
	PosY.f = (50 * Sin(Radian(Angle / 2))) + 65
	PosZ.f = 75 * Cos(Radian(Angle))
	MoveLight(#LIGHT_ONE, PosX, PosY + 100, PosZ)
	SetLightColor(#LIGHT_TWO, #PB_Light_SpecularColor, RGB(255, Random(200), 0))
	MoveCamera(#CAMERA, PosX, PosY, PosZ, #PB_Absolute)
	CameraLookAt(#CAMERA, 0, 60, 0)
	RenderWorld()
	FlipBuffers()

	ExamineKeyboard()
	If KeyboardReleased(#PB_Key_Escape)
		Quit = #True
	EndIf
Until Quit = #True Or event = #PB_Event_CloseWindow
End
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: torch demo with AttachEntityObject()

Post by DK_PETER »

@applePi

I didn't know that it was fixed! :shock:
Thanks for letting me know. That's really GREAT news.
I was getting a bit tired adding bones to objects, which didn't really need it. :)
I'll upgrade to 5.31 b1 right away.

Edit: Yes!!!! YEEEES!!!!! It truly works!!!! Both x86 and x64

@Team
Thank you!! :D
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply