example from the book PureBasic - A Beginners Guide

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

example from the book PureBasic - A Beginners Guide

Post by applePi »

i have found a good example in the book PureBasic - A Beginners Guide http://www.purebasic.fr/english/viewtopic.php?t=37059 its graphics like this
Image
it has a real flame in the hands of delphi, it has a spherical map defined in script file with env_map spherical . the env mapping here seems fake reflection and not real time, since i put a red cube in front of the delphi and i light it but it does not show on the body of delphi
for who want to try it in PB 5.20 beta5 download the code from the author page above, and go to example 221 , change the code to this (i have added a red cube)
PS: if you want a chromium/copper steel use the material script and texture under the Porcelain and Steel title in this page http://www.ogre3d.org/tikiwiki/Materials
just change the material name in the script to material Statue instead of material porcelainshad, since Statue is what is written inside the Statue.mesh file . the book describe the code in page 221 (the same as code number)
PS: the real time reflection solved in this thread http://www.purebasic.fr/english/viewtop ... 36&t=55460 using cube mapping

Code: Select all

Enumeration
	#MESH
	#TEXTURE
	#MATERIAL
	#ENTITY
	#CAMERA_ONE
	#LIGHT_ONE
	#LIGHT_TWO
	#LIGHT_Three
	#PARTICLE_ONE
	#cube
EndEnumeration

;Set the width, height and bit depth of the screen
;Abbreviated variables are used here due to page width constraints :(
Global ScrW.l = 1024
Global ScrH.l = 768
;Global ScrW.l = 640
;Global ScrH.l = 480
Global ScrD.l = 32
;Other global variables
Global Quit.b = #False

;Simple error checking procedure
Procedure HandleError(Result.l, Text.s)
	If Result = 0
		MessageRequester("Error", Text, #PB_MessageRequester_Ok)
		End
	EndIf
EndProcedure

;Initialize environment
HandleError(InitEngine3D(), "InitEngine3D() command failed.")
HandleError(InitSprite(), "InitSprite() command failed.")
HandleError(OpenScreen(ScrW, ScrH, ScrD, ""), "Could not open screen.")
HandleError(InitKeyboard(), "InitKeyboard() command failed.")
SetFrameRate(60)

Add3DArchive("Data\", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
Parse3DScripts()
CreateEntity(#ENTITY, LoadMesh(#MESH, "Statue.mesh"), #PB_Material_None)
;just a  cube to test reflection
CreateCube(#cube,10)
    CreateMaterial(1, LoadTexture(0, "Geebee2.bmp"))
    MaterialCullingMode(1, #PB_Material_NoCulling)
    DisableMaterialLighting(1, 0)
    ;MaterialShininess(1, 220)
    ;SetMaterialColor(1, #PB_Material_SelfIlluminationColor, RGB(0,0,255))
    CreateEntity(#cube,  MeshID(#cube), MaterialID(1))
    MoveEntity(#cube, 10,50,20)
    
LoadTexture(#TEXTURE, "Flame.png")
	CreateMaterial(#MATERIAL, TextureID(#TEXTURE))
	DisableMaterialLighting(#MATERIAL, 1)
	MaterialBlendingMode(#MATERIAL, #PB_Material_Add)

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

CreateLight(#LIGHT_ONE, RGB(255,255,255))
CreateLight(#LIGHT_TWO, RGB(255, 200, 0), 12.9, 72, 15.7)
CreateLight(#LIGHT_Three, RGB(0, 255, 0), 10,50,10)
LightLookAt(#LIGHT_Three, 10,50,20)

CreateCamera(#CAMERA_ONE, 0, 0, 100, 100)

;Main loop
Repeat

	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)
	;LightColor(#LIGHT_TWO, RGB(255, Random(200), 0))
	SetLightColor(#LIGHT_TWO, #PB_Light_SpecularColor, RGB(255, Random(200), 0))

	MoveCamera(#CAMERA_ONE, PosX, PosY, PosZ,#PB_Absolute)
	CameraLookAt(#CAMERA_ONE, 0, 60, 0)
	RenderWorld()
	FlipBuffers()

	ExamineKeyboard()
	If KeyboardReleased(#PB_Key_Escape)
		Quit = #True
	EndIf
Until Quit = #True
End