CSE 682: MEL tasks
Assignment: Complete the following MEL programming tasks
Half credit will be given for tasks submitted up to 2 days late (zero after that).
You will demo your work to me on Monday, February 2.
NOTE: Because of the weather-cancelled class, the demos are postponed until Feb. 4
- bouncing ball
- use MEL commands to:
- create a sphere
- add attributes of vx and vy and initialize to reasonable values
- create an expression that
- if it's frame 1, reset the ball to the origin and reinitialize velocity
- otherwise update position by adding the velocity to it and add a constant (negative) acceleration to the ball's y velocity
- if the ball's y value is less than zero, set it to zero, set velocity to original velocity times scale factor, scale down scale factor
- spring connected balls - you will interactively move one and the other will move as if attached as a spring
- use MEL commands
- create 2 balls, b1 and b2
- to b2, add attributes of velocity in x, y, z
- create an expression
- if it's frame 1, reset b2 to the origin and reinitialize velocity to zero
- else
- compute the vector between the two balls, d = p1-p2
- compute the distance between the two balls, dist
- normalize d by dividing through by dist
- get the relative velocity of the balls into a vector, v = v1-v2
- compute the spring force using spring and damper constants, ks and kd
f = ks*dist*d - kd*(v.d)*d (where 'v.d' means 'dot product')
This will pull b2 right on top of b1. If you want to maintain a separation of 'L', the use
f = ks*(dist-L)*d - kd*(v.d)*d
- using the mass of b2, compute the acceleration for b2
a = f/m
- add the acceleration to the velocity of b2
v = v + a
- add the velocity to the position of b2
p = p + v
- after setting the current frame to something other than 1, interactively grab b1 and move it around. b2 should follow as if connected by a spring.
- During you debugging phase, you can recenter b2 by setting the frame to 1.
- set the frame to something other than 1, then drag b1 around interactively or script some sinusoidal pseudo random motion to b1. b2 should follow it around as if attached by a spring, having some springyness to it but without going wild.
- you need to set some constants to make this work: ks, kd, and m.
I would suggest setting all to '1'.
Increasing 'm' will make the ball have more inertia.
Increasing ks and kd increase the spring force and damper force, respectively.
See what works.
- you may need to add a fudge factor to control velocity - you don't need to be physically correct, you need to make it look good.
You can scale down the final velocity or clamp it to a certain maximum.
- you might want to get it going in one dimension first (e.g. along the x-axis) to make sure you have the basics correct, then go to 2 dimensions, then 3.
- Obvisouly, there is no one right answer to this - this is not physical simulation: it doesn't have to be accurate, it has to look good.
Part of the objective is to get you to play around with the equation until you get an acceptable motion.