home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-02-20 | 3.1 KB | 103 lines | [AMAS/AMAP] |
- // -* AnnotationBehavior.js *-
- //
- // Name: Annotation behavior
- // Description:
- // Author:
- // Version: $Id: AnnotationBehavior.js,v 1.7 2001/01/03 10:51:50 consumer Exp $
- //
-
- // Keep an array of the solids using this behavior
- var annotationSolids = new Array(1);
-
- function AnnotationBehavior(solidName, text, size, camera)
- {
- // Member methods of the behavior
- this.start = AnnotationBehaviorStart;
- this.stop = AnnotationBehaviorStop;
-
- // Member variables of the behavior
- this.cameraId = camera;
- this.solidId = TSMakeUniqID("AnnotationSolid_" + solidName);
- this.textId = TSMakeUniqID("AnnotationText_" + solidName);
- this.axisId = TSMakeUniqID("AxisLink_" + solidName);
-
- // Initialize the behavior
- var solidPos = TSSolidGetPosition(solidName);
- var position = TSMakePoint(solidPos.x, solidPos.y + TSSolidGetLengthY(solidName) * 0.8, solidPos.z);
-
- // Make a new solid
- TSMakeSolid(this.solidId, '0', TSMakeStringFromPoint(position));
- TSSetAttribute(this.solidId, 'mass', '0');
- TSAppendChild(TSGetSceneId(), this.solidId);
-
- // Make axis link
- var axis = TSMakePoint(0, 1, 0);
- var point = TSMakePoint(0, 0, 0);
- TSMakeAxisLink(this.axisId, axis, point, this.solidId)
- TSAppendChild(solidName, this.axisId);
- TSUpdateNode(solidName);
-
- // Make a text
- TSMakeText(this.textId, text, 1, '1 1 1');
- TSAppendChild(this.solidId, this.textId);
-
- TSUpdateNodeAttribute(this.textId, 'visible', '0');
- TSUpdateNode(this.solidId);
-
- // Calculate the size of the text
- var len1 = TSSolidGetLengthX(solidName);
- var len2 = TSSolidGetLengthX(this.solidId);
- var s = (len1 / len2) * size;
- var thickness = TSSolidGetLengthZ(solidName) / 20.0;
-
- TSSetAttribute(this.textId, 'size', s.toString());
- TSSetAttribute(this.textId, 'thickness', thickness.toString());
- TSUpdateNode(this.textId);
- }
-
- function AnnotationBehaviorStart()
- {
- var position = TSCameraGetPosition(this.cameraId);
- var targetPoint = TSCameraGetTargetPosition(this.cameraId);
-
- // Create the vector between the camera and the target point (in spherical coordinates)
- var sphericCoords = TSVectorToSphericCoords(TSMakeVector(targetPoint, position));
- var phiDeg = TSRadToDeg(sphericCoords.phi);
- var thetaDeg = TSRadToDeg(sphericCoords.theta);
- var rot = TSMakeStringFromPoint(TSMakePoint(0, thetaDeg, 0));
-
- TSUpdateNodeAttribute(this.solidId, 'rotation', rot);
- TSUpdateNodeAttribute(this.textId, 'visible', '1');
- }
-
- function AnnotationBehaviorStop()
- {
- TSUpdateNodeAttribute(this.textId, 'visible', '0');
- }
-
- //
- // Event functions
- //
-
- function AnnotationBehaviorStartEvent(obj, event)
- {
- if (annotationSolids[obj] == null) {
- var text = TSGetExtraParam(event, 'text');
- var size = TSGetExtraParam(event, 'size');
- var camera = TSGetExtraParam(event, 'camera');
- var targetSolid = TSGetExtraParam(event, 'targetSolid');
-
- if (targetSolid == "")
- annotationSolids[obj] = new AnnotationBehavior(obj, text, size, camera);
- else
- annotationSolids[obj] = new AnnotationBehavior(targetSolid, text, size, camera);
- }
-
- annotationSolids[obj].start();
- }
-
- function AnnotationBehaviorStopEvent(obj, event)
- {
- annotationSolids[obj].stop();
- }
-