Graphics Reference
In-Depth Information
Listing 35.3: Specialized net force function.
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
// Net force on all objects
Vector3[n] f (float t, Vector3[n] y, Vector3[n] v) {
Vector3[n] net;
// for each object
for(inti=0;i<n;++i) {
net[i] += F gravity (i) + F buoyancy (t, y, i);
for (int j in objectsNeariWithHigherIndex(i, y)) {
Vector3 fi =
F friction (t, y, v, i, j) + F normal (y, i, j);
Vector3 fj = -fi;
net[i] += fi;
net[j] += fj;
}
}
// for each pair connected by a spring
for(ints=0;s<numSprings; ++s) {
int i = spring[s].index[0];
int j = spring[s].index[1];
Vector3 fi =
F spring (y, v, i, j);
Vector3 fj = -fi;
net[i] += fi;
net[j] += fj;
}
return net;
}
Note that we use subscripts to denote the kind of force pair. For example, the
force of gravity is denoted F gravity . This is a standard notation in physics, although
it is unusual in math. It follows our convention that subscripts denoting meaning
(like “gravity” or the “i” and “o” for “incoming” and “outgoing”) are typeset in
roman font, while subscripts indicating indexing are treated as variables and type-
set in italic. The “gravity” is part of the name of the function, not a variable. In
equations we'll shorten this to just F g .
Most force functions depend on additional constants that are not explicit argu-
ments. This means that in an actual implementation they would have access to
additional information about each object (maybe through applying the provided
indices to a global scene array). This is reminiscent of the typical design for a
BSDF implementation, where the canonical incoming and outgoing light direc-
tion vector arguments are augmented by member variables such as reflectivity and
index of refraction.
g ( y , i , j )
i
35.6.4.1 Gravity
Assume that the object with index i is a point mass and that the object with index
j is a sphere (or a second point mass). By Newton's law of universal gravitation,
the gravitational force experienced by object i (at y i ) due to object j (at y j )is
m i m j
y j
y i
F g ( y , i , j )= G
.
(35.39)
||
y j
y i ||
2
||
y j
y i ||
g ( y , j , i )
j
This remains a good approximation if the radius of the bounding sphere around
each object is small compared to the distance between them (e.g., for computing
the forces that planets and stars exert on one another).
Figure 35.20: Forces due to grav-
ity between two bodies.
Search WWH ::




Custom Search