All comments have been omitted to make the post short.
Code: Select all
function main()
print("Please press 'y' if you want to use realtime shadows.")
local shadows = io.read("*line")
local installPath = "../../../../"
print("Please select the driver you want for this example:\n" ..
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.2\n" ..
" (d) Software Renderer\n (e) NullDevice\n (otherKey) exit\n\n")
local answer = io.read("*line")
local driverTypes = {["a"] = irr.video.EDT_DIRECTX9,
["b"] = irr.video.EDT_DIRECTX8,
["c"] = irr.video.EDT_OPENGL,
["d"] = irr.video.EDT_SOFTWARE,
["e"] = irr.video.EDT_NULL }
local type = driverTypes[answer]
if type == nil then
return 1
end
local device = irr.createDevice(type, irr.core.dimension2d(640, 480), 16, false, (shadows == "y") or (shadows == "yes"))
if device == nil then
return 1 -- could not create selected driver.
end
local driver = device:getVideoDriver()
local smgr = device:getSceneManager()
local mesh = smgr:getMesh(installPath .. "media/room.3ds");
smgr:getMeshManipulator():makePlanarTextureMapping(mesh:getMesh(0), 0.004)
local node = smgr:addAnimatedMeshSceneNode(mesh)
node:setMaterialTexture(0, driver:getTexture(installPath .. "media/rockwall.bmp"))
node:getMaterial(0).EmissiveColor:set(0,0,0,0)
mesh = smgr:addHillPlaneMesh("myHill",
irr.core.dimension2df32(20,20),
irr.core.dimension2d(40,40), nil, 0,
irr.core.dimension2df32(0,0),
irr.core.dimension2df32(10,10))
node = smgr:addWaterSurfaceSceneNode(mesh:getMesh(0), 3, 300, 30)
node:setPosition(irr.core.vector3d(0,7,0))
node:setMaterialTexture(0, driver:getTexture(installPath .. "media/water.jpg"))
node:setMaterialTexture(1, driver:getTexture(installPath .. "media/stones.jpg"))
node:setMaterialType(irr.video.EMT_REFLECTION_2_LAYER)
node = smgr:addLightSceneNode(nil, irr.core.vector3d(0,0,0),
irr.video.SColorf(1.0, 0.6, 0.7, 1.0), 600.0)
local anim = smgr:createFlyCircleAnimator(irr.core.vector3d(0,150,0),250.0)
node:addAnimator(anim)
anim:drop()
node = smgr:addBillboardSceneNode(node, irr.core.dimension2df32(50, 50))
node:setMaterialFlag(irr.video.EMF_LIGHTING, false)
node:setMaterialType(irr.video.EMT_TRANSPARENT_ADD_COLOR)
node:setMaterialTexture(0, driver:getTexture(installPath .. "media/particlewhite.bmp"))
local ps = smgr:addParticleSystemSceneNode(false)
ps:setPosition(irr.core.vector3d(-70,60,40))
ps:setScale(irr.core.vector3d(2,2,2))
ps:setParticleSize(irr.core.dimension2df32(20.0, 20.0))
local em = ps:createBoxEmitter(
irr.core.aabbox3d(-7,0,-7,7,1,7),
irr.core.vector3d(0.0,0.06,0.0),
80,100,
irr.video.SColor(0,255,255,255), irr.video.SColor(0,255,255,255),
800,2000)
ps:setEmitter(em)
em:drop()
local paf = ps:createFadeOutParticleAffector()
ps:addAffector(paf)
paf:drop()
ps:setMaterialFlag(irr.video.EMF_LIGHTING, false)
ps:setMaterialType(irr.video.EMT_TRANSPARENT_ADD_COLOR)
ps:setMaterialTexture(0, driver:getTexture(installPath .. "media/fire.bmp"))
mesh = smgr:getMesh(installPath .. "media/faerie.md2")
local anode = smgr:addAnimatedMeshSceneNode(mesh)
anode:setPosition(irr.core.vector3d(-50,65,-60))
anode:setScale(irr.core.vector3d(2,2,2))
anode:setMD2Animation(irr.scene.EMAT_STAND)
anode:setMaterialTexture(0, driver:getTexture(installPath .. "media/Faerie5.BMP"))
anode:addShadowVolumeSceneNode()
smgr:setShadowColor(irr.video.SColor(150,0,0,0))
local camera = smgr:addCameraSceneNodeFPS()
camera:setPosition(irr.core.vector3d(-50,50,-150))
device:getCursorControl():setVisible(false)
local lastFPS = -1
while device:run() do
if device:isWindowActive() then
driver:beginScene(true, true, nil)
smgr:drawAll()
driver:endScene()
local fps = driver:getFPS()
if lastFPS ~= fps then
local str = "Irrlicht Engine - SpecialFX example ["
str = str .. driver:getName()
str = str .. "] FPS:"
str = str .. fps
device:setWindowCaption(str)
lastFPS = fps
end
end
end
device:drop()
return 0
end
main()