dark-hammer / test-data / test6.lua

s = eng.scene()
s:clear()

s:createModel("ground", "test-data/plane.h3dm")

eng.setSunDir(1, -1, 0)
eng.setSunIntensity(1)
eng.setAmbientSky(128, 128, 128)
eng.setAmbientGround(230, 255, 230)
s:setGravity(0, -98, 0)
s:createPhysicsPlane()

function spawn_obj(s, name, pos, model_file, rigid_file)
	local obj = s:createModel(name, model_file)
	obj:addRigidBody(rigid_file)
	obj:move(pos)
	--obj:rotate(core.randRangeFloat(0, 360), core.randRangeFloat(0, 360), 0)
	return obj
end

obj_cnt = 1
radius = 1
a = 1
step = math.pi/12
t = 0
first_decr = false
second_decr = false
init_decr = false
while t <= 6*math.pi do
	obj = spawn_obj(s, "domino", core.vec3(0, 0, 0), "test-data/domino.h3dm", "test-data/domino.h3dp")	

	obj:move(a*t*math.cos(t), 0, a*t*math.sin(t))
	obj:rotate(0, 1-math.deg(t), 0)
	t = t + step
	if t > math.pi and not init_decr then
		step = math.pi/35
		init_decr = true
	end
		
	if t > 3*math.pi and not first_decr then
		step = step - step*0.4
		first_decr = true
	end
	
	if t > 5*math.pi and not second_decr then
		step = step - step*0.2
		second_decr = true
	end
end

function throw_ball(id)
	ball:addForce(100, 0, 0)
	eng.removeTimer(id)
end

function spawn_ball(id)
	ball = spawn_obj(s, "ball", core.vec3(-0, 3, -0.52), "test-data/sphere.h3dm",
	"test-data/sphere.h3dp")
	--eng.addTimer(10, "throw_ball")
	eng.removeTimer(id)
end

function trigger_test(trigger_id, other_id, state)
	if state == eng.TRIGGER_IN then 
		core.printcon(s:getObject(other_id):name() .. " " .. "IN")
	elseif state == eng.TRIGGER_OUT then
		core.printcon(s:getObject(other_id):name() .. " " .. "OUT")
	end
end

eng.addTimer(5000, "spawn_ball")

tr = s:createTrigger("trigger", 1, 1, 1, "trigger_test")
tr:set3f("trigger", "local_pos", 0, 0.5, 0)
tr:move(0, 0.2, -2)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.