-
Notifications
You must be signed in to change notification settings - Fork 0
/
demoShapes.lua
executable file
·120 lines (107 loc) · 3.53 KB
/
demoShapes.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
-- Example of script defining a simple world.
--
-- Units:
-- - distances & coordinates : m
-- - mass : kg
-- - density : kg/m^3
local Demo = require("demos/Demo")
local demoShapes = Demo.new({
name= "shapes",
description= "List of possible shapes in the physics engine.",
})
function demoShapes.exec()
Demo.placeCamera({0,1,6},{0,1,0})
local world = insight.world
-- List of object added into the world by this script.
print("Currently 5 different basic shapes can be inserted via Lua.")
objects= {}
print("1 - StaticPlane shape (cannot move), used for the ground")
objects.terrain = insight.world:newBody({
shape= {
type= "StaticPlane",
params= {
normal= {0,1,0}, -- normal vector of the plane.
offset= 0 -- the point origin+offset*normal is in the plane (here {0,0,0})
},
},
})
print("2 - Sphere shape")
objects.sphere = world:newBody({
shape= {
type= "Sphere",
params= {
radius= 0.3,
density= 1000,
-- mass can be specified instead of density.
},
},
})
objects.sphere:setPosition({3, 0.5, 0})
print("3 - Cylinder shape")
-- In default orientations, the cylinder is Y-axis aligned.
objects.cylinder = world:newBody({
shape= {
type="Cylinder",
params= {
halfExtents= {1, 0.5, 1}, -- 2m radius, 1m height.
mass= 15000,
-- density can be specified instead of mass.
},
},
})
objects.cylinder:setPosition({1, 0.5, 0})
print("4 - Cuboid shape")
objects.cuboid = world:newBody({
shape= {
type= "Cuboid",
params= {
halfExtents= {0.2,0.7,0.3},
density= 1200,
-- mass can be specified instead of density.
},
},
})
objects.cuboid:setPosition({-1,0.35,0})
print("5 - Convex hull shape (here a pyramid)")
objects.pyramid = world:newBody({
shape= {
type= "ConvexHull",
params= {
mass= 200,
vertices= {
{-0.5,-0.2,-0.5},
{-0.5,-0.2, 0.5},
{ 0.5,-0.2, 0.5},
{ 0.5,-0.2,-0.5},
{ 0, 0.4, 0},
},
},
},
})
objects.pyramid:setPosition({-2,0.2,0})
print("")
print("It is possible to combine the basic shapes to make concave objects (here a table)")
objects.table = world:newBody({
shape= {
type= "Compound",
params= {
children= {
{
transform={position={0,0.2,0}, rotation={0,0,0,1}},
shape= {type="Cylinder", params={density=2000, halfExtents={0.75,0.05,0.75}}},
},{
transform={position={0,-0.6,0}, rotation={0,0,0,1}},
shape= {type="Cuboid", params={density=2000, halfExtents={0.3,0.075,0.3}}},
},{
transform={position={0,-0.2,0}, rotation={0,0,0,1}},
shape= {type="Cylinder", params={density=2000, halfExtents={0.075,0.4,0.075}}},
},
},
},
},
})
objects.table:setPosition({-3, 0.675, 0})
print("")
print("All objects were pushed in the 'objects' global variable.")
end
return demoShapes