125430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams/*
26a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye * Copyright (C) 2013 The Android Open Source Project
325430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams *
425430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
525430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams * you may not use this file except in compliance with the License.
625430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams * You may obtain a copy of the License at
725430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams *
825430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
925430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams *
1025430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams * Unless required by applicable law or agreed to in writing, software
1125430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
1225430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1325430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams * See the License for the specific language governing permissions and
1425430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams * limitations under the License.
1525430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams */
1625430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams
1725430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Samspackage android.renderscript;
1825430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams
199c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines/**
206a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye * Vector version of the basic float type.
216a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye * Provides four float fields packed.
226a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye */
23a70f416c9cf2fc6cc5e132c1d656ce07441d6b82Jason Samspublic class Float4 {
246a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public float x;
256a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public float y;
266a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public float z;
276a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public float w;
286a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
29a70f416c9cf2fc6cc5e132c1d656ce07441d6b82Jason Sams    public Float4() {
3025430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams    }
316a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide */
326a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public Float4(Float4 data) {
336a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.x = data.x;
346a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.y = data.y;
356a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.z = data.z;
366a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.w = data.w;
376a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
3825430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams
396a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public Float4(float x, float y, float z, float w) {
406a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.x = x;
416a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.y = y;
426a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.z = z;
436a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.w = w;
44094a068bc46f725a7358ff84317cff2ca4528601Alex Sakhartchouk    }
45094a068bc46f725a7358ff84317cff2ca4528601Alex Sakhartchouk
466a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
476a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector add
486a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
496a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
506a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
516a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
526a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
536a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static Float4 add(Float4 a, Float4 b) {
546a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        Float4 res = new Float4();
556a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.x = a.x + b.x;
566a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.y = a.y + b.y;
576a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.z = a.z + b.z;
586a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.w = a.w + b.w;
596a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
606a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return res;
616a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
626a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
636a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
646a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector add
656a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
666a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
676a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
686a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void add(Float4 value) {
696a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x += value.x;
706a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y += value.y;
716a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z += value.z;
726a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w += value.w;
736a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
746a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
756a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
766a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector add
776a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
786a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
796a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
806a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void add(float value) {
816a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x += value;
826a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y += value;
836a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z += value;
846a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w += value;
856a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
866a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
876a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
886a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector add
896a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
906a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
916a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
926a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
936a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
946a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static Float4 add(Float4 a, float b) {
956a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        Float4 res = new Float4();
966a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.x = a.x + b;
976a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.y = a.y + b;
986a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.z = a.z + b;
996a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.w = a.w + b;
1006a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1016a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return res;
1026a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
1036a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1046a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
1056a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector subtraction
1066a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
1076a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
1086a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
1096a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void sub(Float4 value) {
1106a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x -= value.x;
1116a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y -= value.y;
1126a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z -= value.z;
1136a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w -= value.w;
1146a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
1156a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1166a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
1176a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector subtraction
1186a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
1196a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
1206a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
1216a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void sub(float value) {
1226a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x -= value;
1236a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y -= value;
1246a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z -= value;
1256a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w -= value;
1266a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
1276a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1286a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
1296a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector subtraction
1306a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
1316a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
1326a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
1336a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
1346a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
1356a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static Float4 sub(Float4 a, float b) {
1366a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        Float4 res = new Float4();
1376a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.x = a.x - b;
1386a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.y = a.y - b;
1396a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.z = a.z - b;
1406a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.w = a.w - b;
1416a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1426a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return res;
1436a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
1446a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1456a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
1466a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector subtraction
1476a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
1486a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
1496a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
1506a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
1516a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
1526a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static Float4 sub(Float4 a, Float4 b) {
1536a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        Float4 res = new Float4();
1546a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.x = a.x - b.x;
1556a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.y = a.y - b.y;
1566a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.z = a.z - b.z;
1576a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.w = a.w - b.w;
1586a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1596a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return res;
1606a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
1616a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1626a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
1636a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector multiplication
1646a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
1656a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
1666a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
1676a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void mul(Float4 value) {
1686a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x *= value.x;
1696a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y *= value.y;
1706a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z *= value.z;
1716a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w *= value.w;
1726a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
1736a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
1746a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
1756a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector multiplication
1766a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
1776a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
1786a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
1796a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void mul(float value) {
1806a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x *= value;
1816a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y *= value;
1826a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z *= value;
1836a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w *= value;
1846a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
18525430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams
1866a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
1876a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector multiplication
1886a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
1896a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
1906a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
1916a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
1926a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
1936a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static Float4 mul(Float4 a, Float4 b) {
1946a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        Float4 res = new Float4();
1956a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.x = a.x * b.x;
1966a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.y = a.y * b.y;
1976a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.z = a.z * b.z;
1986a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.w = a.w * b.w;
19925430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams
2006a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return res;
2016a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
2026a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2036a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
2046a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector multiplication
2056a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
2066a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
2076a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
2086a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
2096a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
2106a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static Float4 mul(Float4 a, float b) {
2116a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        Float4 res = new Float4();
2126a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.x = a.x * b;
2136a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.y = a.y * b;
2146a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.z = a.z * b;
2156a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.w = a.w * b;
2166a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2176a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return res;
2186a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
2196a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2206a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
2216a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector division
2226a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
2236a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
2246a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
2256a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void div(Float4 value) {
2266a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x /= value.x;
2276a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y /= value.y;
2286a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z /= value.z;
2296a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w /= value.w;
2306a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
2316a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2326a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
2336a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector division
2346a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
2356a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
2366a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
2376a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void div(float value) {
2386a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x /= value;
2396a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y /= value;
2406a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z /= value;
2416a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w /= value;
2426a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
2436a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2446a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
2456a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector division
2466a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
2476a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
2486a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
2496a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
2506a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
2516a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static Float4 div(Float4 a, float b) {
2526a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        Float4 res = new Float4();
2536a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.x = a.x / b;
2546a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.y = a.y / b;
2556a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.z = a.z / b;
2566a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.w = a.w / b;
2576a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2586a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return res;
2596a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
2606a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2616a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
2626a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector division
2636a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
2646a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
2656a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
2666a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
2676a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
2686a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static Float4 div(Float4 a, Float4 b) {
2696a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        Float4 res = new Float4();
2706a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.x = a.x / b.x;
2716a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.y = a.y / b.y;
2726a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.z = a.z / b.z;
2736a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        res.w = a.w / b.w;
2746a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2756a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return res;
2766a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
2776a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2786a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
2796a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector dot Product
2806a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
2816a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
2826a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
2836a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
2846a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public float dotProduct(Float4 a) {
2856a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return (x * a.x) + (y * a.y) + (z * a.z) + (w * a.w);
2866a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
2876a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2886a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
2896a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector dot Product
2906a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
2916a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
2926a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param b
2936a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
2946a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
2956a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public static float dotProduct(Float4 a, Float4 b) {
2966a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return (b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w);
2976a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
2986a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
2996a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
3006a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * Vector add Multiple
3016a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
3026a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
3036a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param factor
3046a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
3056a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void addMultiple(Float4 a, float factor) {
3066a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x += a.x * factor;
3076a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y += a.y * factor;
3086a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z += a.z * factor;
3096a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w += a.w * factor;
3106a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
3116a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
3126a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
3136a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * set vector value by float4
3146a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
3156a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param a
3166a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
3176a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void set(Float4 a) {
3186a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.x = a.x;
3196a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.y = a.y;
3206a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.z = a.z;
3216a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.w = a.w;
3226a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
3236a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
3246a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
3256a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * set vector negate
3266a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
3276a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void negate() {
3286a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        x = -x;
3296a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        y = -y;
3306a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        z = -z;
3316a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        w = -w;
3326a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
33325430d0734d12d12ca2d2d7a9d18c0cf3c5bdc4eJason Sams
3346a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
3356a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * get vector length
3366a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
3376a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
3386a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
3396a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public int length() {
3406a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return 4;
3416a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
3426a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
3436a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
3446a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * return the element sum of vector
3456a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
3466a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
3476a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
3486a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public float elementSum() {
3496a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        return x + y + z + w;
3506a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
3516a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
3526a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
3536a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * get the vector field value by index
3546a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
3556a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param i
3566a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @return
3576a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
3586a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public float get(int i) {
3596a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        switch (i) {
3606a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 0:
3616a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return x;
3626a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 1:
3636a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return y;
3646a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 2:
3656a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return z;
3666a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 3:
3676a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return w;
3686a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        default:
3696a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            throw new IndexOutOfBoundsException("Index: i");
3706a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        }
3716a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
3726a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
3736a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
3746a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * set the vector field value by index
3756a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
3766a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param i
3776a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
3786a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
3796a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void setAt(int i, float value) {
3806a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        switch (i) {
3816a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 0:
3826a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            x = value;
3836a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return;
3846a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 1:
3856a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            y = value;
3866a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return;
3876a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 2:
3886a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            z = value;
3896a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return;
3906a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 3:
3916a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            w = value;
3926a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return;
3936a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        default:
3946a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            throw new IndexOutOfBoundsException("Index: i");
3956a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        }
3966a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
3976a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
3986a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
3996a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * add the vector field value by index
4006a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
4016a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param i
4026a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param value
4036a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
4046a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void addAt(int i, float value) {
4056a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        switch (i) {
4066a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 0:
4076a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            x += value;
4086a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return;
4096a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 1:
4106a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            y += value;
4116a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return;
4126a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 2:
4136a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            z += value;
4146a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return;
4156a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        case 3:
4166a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            w += value;
4176a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            return;
4186a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        default:
4196a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye            throw new IndexOutOfBoundsException("Index: i");
4206a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        }
4216a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
4226a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
4236a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
4246a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * set the vector field value
4256a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
4266a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param x
4276a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param y
4286a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param z
4296a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param w
4306a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
4316a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void setValues(float x, float y, float z, float w) {
4326a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.x = x;
4336a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.y = y;
4346a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.z = z;
4356a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        this.w = w;
4366a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
4376a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye
4386a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    /** @hide
4396a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * copy the vector to float array
4406a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     *
4416a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param data
4426a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     * @param offset
4436a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye     */
4446a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    public void copyTo(float[] data, int offset) {
4456a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        data[offset] = x;
4466a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        data[offset + 1] = y;
4476a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        data[offset + 2] = z;
4486a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye        data[offset + 3] = w;
4496a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye    }
4506a5875cf96a6eebf4ef2e176176868ecbf17122fMatthieu Delahaye}
451