Ejemplo n.º 1
0
 update(context, parent) {
   super.update(context, parent);
   if (this.hasChanged) {
     // The line should point the ground...
     let center = vec3.create();
     vec3.transformMat4(center, center, this.globalMatrix);
     let point = vec3.create();
     vec3.copy(point, center);
     point[1] = 0;
     // Scale the line to match the size
     this.guideLine.transform.scale[0] = center[1];
     // Here comes the hard part... setting rotation.
     let hand = vec4.fromValues(0, -1, 0, 0);
     let inv = mat4.create();
     mat4.invert(inv, this.globalMatrix);
     vec4.transformMat4(hand, hand, inv);
     vec4.normalize(hand, hand);
     quat.rotationTo(this.guideLine.transform.rotation, [1, 0, 0], hand);
     this.guideLine.transform.invalidate();
   }
 }
Ejemplo n.º 2
0
    getTimedValue (value_type, currTime, maxTime, animation, animationBlock) {
        function convertInt16ToFloat(value){
            return (((value < 0) ? value + 32768 : value - 32767)/ 32767.0);
            //return (value / 32768) - 1.0
        }

        function convertValueTypeToVec4(value, type){
            if (type == 0) {
                return [value.x, value.y, value.z, 0];
            } else if (type == 1) {
                return [convertInt16ToFloat(value[0]),
                    convertInt16ToFloat(value[1]),
                    convertInt16ToFloat(value[2]),
                    convertInt16ToFloat(value[3])];
            } else if (type == 2) {
                return [value/32767,value/32767, value/32767, value/32767];
            } else if (type == 3) {
                return [value.x,value.y, value.z, value.w];
            }
        }

        var globalSequence = animationBlock.global_sequence;
        var interpolType = animationBlock.interpolation_type;

        var times = animationBlock.timestampsPerAnimation[animation];
        var values =  animationBlock.valuesPerAnimation[animation];

        //Hack
        if (times == undefined) {
            animation = 0;
            times = animationBlock.timestampsPerAnimation[animation];
            values =  animationBlock.valuesPerAnimation[animation];
        }
        if (times.length == 0) {
            return undefined;
        }

        if (globalSequence >=0) {
            maxTime = this.m2Geom.m2File.globalSequences[globalSequence];
        }

        var times_len = times.length;
        var result;
        if (times_len > 1) {
            //var maxTime = times[times_len-1];
            var animTime = currTime % maxTime;

            if (animTime > times[times_len-1] && animTime <= maxTime) {
                result = convertValueTypeToVec4(values[0], value_type);
            } else {
                result =  convertValueTypeToVec4(times[times_len-1], value_type);
                for (var i = 0; i < times_len; i++) {
                    if (times[i] > animTime) {
                        var value1 = values[i - 1];
                        var value2 = values[i];

                        var time1 = times[i - 1];
                        var time2 = times[i];

                        value1 = convertValueTypeToVec4(value1, value_type);
                        value2 = convertValueTypeToVec4(value2, value_type);

                        result = this.interpolateValues(animTime,
                            interpolType, time1, time2, value1, value2, value_type);

                        if (value_type == 1 || value_type == 3) {
                            vec4.normalize(result, result); //quaternion has to be normalized after lerp operation
                        }

                        break;
                    }
                }
            }
        } else {
            result = convertValueTypeToVec4(values[0], value_type);
        }

        return result;
    }