All Downloads are FREE. Search and download functionalities are using the official Maven repository.

skadistats.clarity.io.decoder.VectorDecoder Maven / Gradle / Ivy

Go to download

Clarity is an open source replay parser for Dota 2 and CSGO 1 and 2 written in Java.

There is a newer version: 3.1.1
Show newest version
package skadistats.clarity.io.decoder;

import skadistats.clarity.io.bitstream.BitStream;
import skadistats.clarity.model.Vector;

public class VectorDecoder implements Decoder {

    private final Decoder floatDecoder;
    private final boolean normal;


    public VectorDecoder(Decoder floatDecoder, boolean normal) {
        this.floatDecoder = floatDecoder;
        this.normal = normal;
    }

    @Override
    public Vector decode(BitStream bs) {
        var v = new float[3];
        v[0] = floatDecoder.decode(bs);
        v[1] = floatDecoder.decode(bs);
        if (!normal) {
            v[2] = floatDecoder.decode(bs);
        } else {
            var s = bs.readBitFlag();
            var p = v[0] * v[0] + v[1] * v[1];
            if (p < 1.0f) v[2] = (float) Math.sqrt(1.0f - p);
            if (s) v[2] = -v[2];
        }
        return new Vector(v);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy