PDA

View Full Version : Objects named 'head' turn to face camera before deleted


jedavis
06-19-2008, 02:42 PM
I spent a little while trying to figure out this little anomoly: characters turning to face the camera when deleted.

It turns out any object or sub-object named "head" will turn to face the camera when the instance is deleted.

Maybe this information is worth a thread...

DrJim
06-19-2008, 07:12 PM
Actually I believe the head returns to its original position rather than turning to face the camera. I have assume this was partially an artifact of having to clear the coordinate references for the deleted object and partially (like the spin) an attept to add a bit of humor as the necessary housekeeping took place.

jedavis
06-20-2008, 03:50 PM
Here is the code that does it... for those who are interested:


edu.cmu.cs.stage3.alice.core.Element[] heads = model.search( namedHeadCriterion );
if( (heads != null) && (heads.length > 0) ) {
edu.cmu.cs.stage3.alice.core.Element head = heads[0];
if( head instanceof edu.cmu.cs.stage3.alice.core.Transformable ) {
edu.cmu.cs.stage3.alice.core.Camera camera = authoringTool.getCurrentCamera();
if( camera != null ) {
edu.cmu.cs.stage3.alice.core.response.PointAtAnima tion pointAt = new edu.cmu.cs.stage3.alice.core.response.PointAtAnima tion();
pointAt.subject.set( head );
pointAt.target.set( camera );
pointAt.duration.set( new Double( .5 ) );
doInOrder.componentResponses.add( pointAt );
edu.cmu.cs.stage3.alice.core.response.Wait wait2 = new edu.cmu.cs.stage3.alice.core.response.Wait();
wait2.duration.set( new Double( .4 ) );
doInOrder.componentResponses.add( wait2 );
}
}
}

model.search( namedHeadCriterion ); returns an array of elements (sub-objects) that meet the "namedHeadCriterion", that is, those that are named "head". (I'm leaving out the "namedHeadCriterion" code)

if( (heads != null) && (heads.length > 0) ) means "if we found a piece named 'head' in the model".

heads[0] is our element named "head". Since objects can't be named the same thing there can be only one.

The rest of the code is more obvious.. it just sets up the PointAtAnimation (turn the subject, "head," to point at the target, "camera") and does it. (helpful hint: in the Alice code "methods" are referred to as "responses")