001/*
002Copyright 2006 Jerry Huxtable
003
004Licensed under the Apache License, Version 2.0 (the "License");
005you may not use this file except in compliance with the License.
006You may obtain a copy of the License at
007
008   http://www.apache.org/licenses/LICENSE-2.0
009
010Unless required by applicable law or agreed to in writing, software
011distributed under the License is distributed on an "AS IS" BASIS,
012WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013See the License for the specific language governing permissions and
014limitations under the License.
015*/
016
017package com.jhlabs.vecmath;
018
019/**
020 * Vector math package, converted to look similar to javax.vecmath.
021 */
022public class Vector4f extends Tuple4f {
023
024        public Vector4f() {
025                this( 0, 0, 0, 0 );
026        }
027        
028        public Vector4f( float[] x ) {
029                this.x = x[0];
030                this.y = x[1];
031                this.z = x[2];
032                this.w = x[2];
033        }
034
035        public Vector4f( float x, float y, float z, float w ) {
036                this.x = x;
037                this.y = y;
038                this.z = z;
039                this.w = w;
040        }
041
042        public Vector4f( Vector4f t ) {
043                x = t.x;
044                y = t.y;
045                z = t.z;
046                w = t.w;
047        }
048
049        public Vector4f( Tuple4f t ) {
050                x = t.x;
051                y = t.y;
052                z = t.z;
053                w = t.w;
054        }
055
056        public float dot( Vector4f v ) {
057                return v.x * x + v.y * y + v.z * z + v.w * w;
058        }
059
060        public float length() {
061                return (float)Math.sqrt( x*x+y*y+z*z+w*w );
062        }
063
064        public void normalize() {
065                float d = 1.0f/( x*x+y*y+z*z+w*w );
066                x *= d;
067                y *= d;
068                z *= d;
069                w *= d;
070        }
071
072}