Розыгрыш Premium и Уникальной юзергруппы на форуме! Перейти


  • УЖЕ ЗАВТРА! Просто зашёл, нажал на кнопку участия и забрал кучу призов уже 30-го декабря: https://yougame.biz/threads/366947/

Пастинг Normalized и DistTo

  • Автор темы Автор темы Irval
  • Дата начала Дата начала
Олдфаг
Олдфаг
Статус
Оффлайн
Регистрация
18 Фев 2019
Сообщения
2,843
Реакции
1,854
Всем привет! Откуда можно спастить Normalized и DistTo для Vector2D (юзать обычный вектор не хочу)? В CSGO Simple и Индусе их нет. Пастчу бэкдроп @bludeck xd
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
.cpp
C++:
Expand Collapse Copy
#include <cmath>

#include "vector_fix.hpp"

VectorDrop::VectorDrop(void)
{

}

VectorDrop::VectorDrop(vec_t X, vec_t Y)
{
    x = X; y = Y;
}

VectorDrop::VectorDrop(vec_t* clr)
{
    x = clr[0]; y = clr[1];
}

//-----------------------------------------------------------------------------
// initialization
//-----------------------------------------------------------------------------

void VectorDrop::Init(vec_t ix, vec_t iy)
{
    x = ix; y = iy;
}

void VectorDrop::Random(float minVal, float maxVal)
{
    x = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal);
    y = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal);
}

void Vector2DClear(VectorDrop& a)
{
    a.x = a.y = 0.0f;
}

//-----------------------------------------------------------------------------
// assignment
//-----------------------------------------------------------------------------

VectorDrop& VectorDrop::operator=(const VectorDrop&vOther)
{
    x = vOther.x; y = vOther.y;
    return *this;
}

//-----------------------------------------------------------------------------
// Array access
//-----------------------------------------------------------------------------

vec_t& VectorDrop::operator[](int i)
{
    return ((vec_t*)this)[i];
}

vec_t VectorDrop::operator[](int i) const
{
    return ((vec_t*)this)[i];
}

//-----------------------------------------------------------------------------
// Base address...
//-----------------------------------------------------------------------------

vec_t* VectorDrop::Base()
{
    return (vec_t*)this;
}

vec_t const* VectorDrop::Base() const
{
    return (vec_t const*)this;
}

//-----------------------------------------------------------------------------
// IsValid?
//-----------------------------------------------------------------------------

bool VectorDrop::IsValid() const
{
    return !isinf(x) && !isinf(y);
}

//-----------------------------------------------------------------------------
// comparison
//-----------------------------------------------------------------------------

bool VectorDrop::operator==(const VectorDrop& src) const
{
    return (src.x == x) && (src.y == y);
}

bool VectorDrop::operator!=(const VectorDrop& src) const
{
    return (src.x != x) || (src.y != y);
}

//-----------------------------------------------------------------------------
// Copy
//-----------------------------------------------------------------------------

void VectorDropCopy(const VectorDrop& src, VectorDrop& dst)
{
    dst.x = src.x;
    dst.y = src.y;
}

void VectorDrop::CopyToArray(float* rgfl) const
{
    rgfl[0] = x; rgfl[1] = y;
}

//-----------------------------------------------------------------------------
// standard Math operations
//-----------------------------------------------------------------------------

void VectorDrop::Negate()
{
    x = -x; y = -y;
}

void VectorDropAdd(const VectorDrop& a, const VectorDrop& b, VectorDrop& c)
{
    c.x = a.x + b.x;
    c.y = a.y + b.y;
}

void VectorDropSubtract(const VectorDrop& a, const VectorDrop& b, VectorDrop& c)
{
    c.x = a.x - b.x;
    c.y = a.y - b.y;
}

void VectorDropMultiply(const VectorDrop& a, vec_t b, VectorDrop& c)
{
    c.x = a.x * b;
    c.y = a.y * b;
}

void VectorDropMultiply(const VectorDrop& a, const VectorDrop& b, VectorDrop& c)
{
    c.x = a.x * b.x;
    c.y = a.y * b.y;
}

void VectorDropDivide(const VectorDrop& a, vec_t b, VectorDrop& c)
{
    vec_t oob = 1.0f / b;
    c.x = a.x * oob;
    c.y = a.y * oob;
}

void VectorDropDivide(const VectorDrop& a, const VectorDrop& b, VectorDrop& c)
{
    c.x = a.x / b.x;
    c.y = a.y / b.y;
}

void VectorDropMA(const VectorDrop& start, float s, const VectorDrop& dir, VectorDrop& result)
{
    result.x = start.x + s * dir.x;
    result.y = start.y + s * dir.y;
}

// FIXME: Remove
// For backwards compatability
void VectorDrop::MulAdd(const VectorDrop& a, const VectorDrop& b, float scalar)
{
    x = a.x + b.x * scalar;
    y = a.y + b.y * scalar;
}

void Vector2DLerp(const VectorDrop& src1, const VectorDrop& src2, vec_t t, VectorDrop& dest)
{
    dest[0] = src1[0] + (src2[0] - src1[0]) * t;
    dest[1] = src1[1] + (src2[1] - src1[1]) * t;
}

//-----------------------------------------------------------------------------
// dot, cross
//-----------------------------------------------------------------------------
vec_t DotProduct2D(const VectorDrop& a, const VectorDrop& b)
{
    return(a.x*b.x + a.y*b.y);
}

// for backwards compatability
vec_t VectorDrop::Dot(const VectorDrop& vOther) const
{
    return DotProduct2D(*this, vOther);
}

vec_t Vector2DNormalize(VectorDrop& v)
{
    vec_t l = v.Length();
    if (l != 0.0f) {
        v /= l;
    }
    else {
        v.x = v.y = 0.0f;
    }
    return l;
}

//-----------------------------------------------------------------------------
// length
//-----------------------------------------------------------------------------
vec_t Vector2DLength(const VectorDrop& v)
{
    return (vec_t)sqrt(v.x*v.x + v.y*v.y);
}

vec_t Vector2DLengthDrop(const VectorDrop& v)
{
    return (vec_t)sqrt(v.x*v.x + v.y*v.y);
}

vec_t VectorDrop::NormalizeInPlace()
{
    return Vector2DNormalize(*this);
}

bool VectorDrop::IsLengthGreaterThan(float val) const
{
    return LengthSqr() > val*val;
}

bool VectorDrop::IsLengthLessThan(float val) const
{
    return LengthSqr() < val*val;
}

vec_t VectorDrop::Length(void) const
{
    return Vector2DLength(*this);
}

vec_t VectorDrop::LengthDrop(void) const
{
    return Vector2DLengthDrop(*this);
}

void Vector2DMin(const VectorDrop&a, const VectorDrop&b, VectorDrop&result)
{
    result.x = (a.x < b.x) ? a.x : b.x;
    result.y = (a.y < b.y) ? a.y : b.y;
}

void Vector2DMax(const VectorDrop&a, const VectorDrop&b, VectorDrop&result)
{
    result.x = (a.x > b.x) ? a.x : b.x;
    result.y = (a.y > b.y) ? a.y : b.y;
}

//-----------------------------------------------------------------------------
// Computes the closest point to vecTarget no farther than flMaxDist from vecStart
//-----------------------------------------------------------------------------
void ComputeClosestPoint2D(const VectorDrop& vecStart, float flMaxDist, const VectorDrop& vecTarget, VectorDrop*pResult)
{
    VectorDrop vecDelta;
    VectorDropSubtract(vecTarget, vecStart, vecDelta);
    float flDistSqr = vecDelta.LengthSqr();
    if (flDistSqr <= flMaxDist * flMaxDist) {
        *pResult = vecTarget;
    }
    else {
        vecDelta /= sqrt(flDistSqr);
        VectorDropMA(vecStart, flMaxDist, vecDelta, *pResult);
    }
}

//-----------------------------------------------------------------------------
// Returns a Vector2D with the min or max in X, Y, and Z.
//-----------------------------------------------------------------------------

VectorDrop VectorDrop::Min(const VectorDrop&vOther) const
{
    return VectorDrop(x < vOther.x ? x : vOther.x, y < vOther.y ? y : vOther.y);
}

VectorDrop VectorDrop::Max(const VectorDrop&vOther) const
{
    return VectorDrop(x > vOther.x ? x : vOther.x, y > vOther.y ? y : vOther.y);
}

//-----------------------------------------------------------------------------
// arithmetic operations
//-----------------------------------------------------------------------------

VectorDrop VectorDrop::operator-(void) const
{
    return VectorDrop(-x, -y);
}

VectorDrop VectorDrop::operator+(const VectorDrop& v) const
{
    VectorDrop res;
    VectorDropAdd(*this, v, res);
    return res;
}

VectorDrop VectorDrop::operator-(const VectorDrop& v) const
{
    VectorDrop res;
    VectorDropSubtract(*this, v, res);
    return res;
}

VectorDrop VectorDrop::operator*(float fl) const
{
    VectorDrop res;
    VectorDropMultiply(*this, fl, res);
    return res;
}

VectorDrop VectorDrop::operator*(const VectorDrop& v) const
{
    VectorDrop res;
    VectorDropMultiply(*this, v, res);
    return res;
}

VectorDrop VectorDrop::operator/(float fl) const
{
    VectorDrop res;
    VectorDropDivide(*this, fl, res);
    return res;
}

VectorDrop VectorDrop::operator/(const VectorDrop& v) const
{
    VectorDrop res;
    VectorDropDivide(*this, v, res);
    return res;
}

VectorDrop operator*(float fl, const VectorDrop& v)
{
    return v * fl;
}

.h

Код:
Expand Collapse Copy
#pragma once

typedef float vec_t;
// 2D Vector
class VectorDrop
{
public:
    // Members
    vec_t x, y, z;
    //float xe, ye, ze;
    // Construction/destruction:
    VectorDrop(void);
    VectorDrop(vec_t X, vec_t Y);
    VectorDrop(vec_t* clr);

    VectorDrop(const VectorDrop&vOther)
    {
        x = vOther.x; y = vOther.y;
    }

    // Initialization
    void Init(vec_t ix = 0.0f, vec_t iy = 0.0f);
    // TODO (Ilya): Should there be an init that takes a single float for consistency?

    // Got any nasty NAN's?
    bool IsValid() const;
    void Invalidate();

    // array access...
    vec_t operator[](int i) const;
    vec_t& operator[](int i);

    // Base address...
    vec_t* Base();
    vec_t const* Base() const;

    // Initialization methods
    void Random(vec_t minVal, vec_t maxVal);
    void Zero(); ///< zero out a vector

                 // equality
    bool operator==(const VectorDrop& v) const;
    bool operator!=(const VectorDrop& v) const;

    // arithmetic operations
    VectorDrop& operator+=(const VectorDrop& v)
    {
        x += v.x; y += v.y;
        return *this;
    }

    VectorDrop& operator-=(const VectorDrop& v)
    {
        x -= v.x; y -= v.y;
        return *this;
    }

    VectorDrop& operator*=(float fl)
    {
        x *= fl;
        y *= fl;
        return *this;
    }

    VectorDrop& operator*=(const VectorDrop& v)
    {
        x *= v.x;
        y *= v.y;
        return *this;
    }

    VectorDrop& operator/=(const VectorDrop& v)
    {
        x /= v.x;
        y /= v.y;
        return *this;
    }

    // this ought to be an opcode.
    VectorDrop& operator+=(float fl)
    {
        x += fl;
        y += fl;
        return *this;
    }

    // this ought to be an opcode.
    VectorDrop& operator/=(float fl)
    {
        x /= fl;
        y /= fl;
        return *this;
    }
    VectorDrop& operator-=(float fl)
    {
        x -= fl;
        y -= fl;
        return *this;
    }

    // negate the vector components
    void Negate();

    // Get the vector's magnitude.
    vec_t Length() const;
    vec_t LengthDrop() const;

    // Get the vector's magnitude squared.
    vec_t LengthSqr(void) const
    {
        return (x*x + y * y);
    }

    // return true if this vector is (0,0,0) within tolerance
    bool IsZero(float tolerance = 0.01f) const
    {
        return (x > -tolerance && x < tolerance &&
            y > -tolerance && y < tolerance);
    }

    vec_t NormalizeInPlace();

    VectorDrop NormalizedDrop() const {
        VectorDrop reses = *this;
        float l = reses.LengthDrop();
        if (l != 0.0f) {
            reses /= l;
        }
        else {
            reses.x = reses.y = reses.z = 0.0f;
        }
        return reses;
    }

    VectorDrop Normalized() const
    {
        return *this / Length();
    }

    bool IsLengthGreaterThan(float val) const;
    bool IsLengthLessThan(float val) const;

    // check if a vector is within the box defined by two other vectors
    bool WithinAABox(VectorDrop const &boxmin, VectorDrop const &boxmax);

    // Get the distance from this vector to the other one.
    //vec_t DistTo(const Vector2D &vOther) const
    //{
    //    Vector delta;

    //    delta.x = x - vOther.x;
    //    delta.y = y - vOther.y;
    //    delta.z = z - vOther.z;

    //    return delta.Length();
    //}

    // Get the distance from this vector to the other one squared.
    // NJS: note, VC wasn't inlining it correctly in several deeply nested inlines due to being an 'out of line' .
    // may be able to tidy this up after switching to VC7
    vec_t DistToDrop(const VectorDrop&vOther) const
    {
        VectorDrop deltar;

        deltar.x = x - vOther.x;
        deltar.y = y - vOther.y;

        return deltar.LengthDrop();
    }

    vec_t DistToSqr(const VectorDrop&vOther) const
    {
        VectorDrop delta;

        delta.x = x - vOther.x;
        delta.y = y - vOther.y;

        return delta.LengthSqr();
    }

    // Copy
    void CopyToArray(float* rgfl) const;

    // Multiply, add, and assign to this (ie: *this = a + b * scalar). This
    // is about 12% faster than the actual vector equation (because it's done per-component
    // rather than per-vector).
    void MulAdd(const VectorDrop& a, const VectorDrop& b, float scalar);

    // Dot product.
    vec_t Dot(const VectorDrop& vOther) const;

    // assignment
    VectorDrop& operator=(const VectorDrop&vOther);

    // 2d
    vec_t Length2D(void) const;
    vec_t Length2DSqr(void) const;

    /// Get the component of this vector parallel to some other given vector
    VectorDrop  ProjectOnto(const VectorDrop& onto);

    // copy constructors
    // Vector2D(const Vector2D &vOther);

    // arithmetic operations
    VectorDrop operator-(void) const;

    VectorDrop operator+(const VectorDrop& v) const;
    VectorDrop operator-(const VectorDrop& v) const;
    VectorDrop operator*(const VectorDrop& v) const;
    VectorDrop operator/(const VectorDrop& v) const;
    VectorDrop operator*(float fl) const;
    VectorDrop operator/(float fl) const;

    // Cross product between two vectors.
    VectorDrop Cross(const VectorDrop&vOther) const;

    // Returns a vector with the min or max in X, Y, and Z.
    VectorDrop Min(const VectorDrop&vOther) const;
    VectorDrop Max(const VectorDrop&vOther) const;
};
 
.cpp
C++:
Expand Collapse Copy
#include <cmath>

#include "vector_fix.hpp"

VectorDrop::VectorDrop(void)
{

}

VectorDrop::VectorDrop(vec_t X, vec_t Y)
{
    x = X; y = Y;
}

VectorDrop::VectorDrop(vec_t* clr)
{
    x = clr[0]; y = clr[1];
}

//-----------------------------------------------------------------------------
// initialization
//-----------------------------------------------------------------------------

void VectorDrop::Init(vec_t ix, vec_t iy)
{
    x = ix; y = iy;
}

void VectorDrop::Random(float minVal, float maxVal)
{
    x = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal);
    y = minVal + ((float)rand() / RAND_MAX) * (maxVal - minVal);
}

void Vector2DClear(VectorDrop& a)
{
    a.x = a.y = 0.0f;
}

//-----------------------------------------------------------------------------
// assignment
//-----------------------------------------------------------------------------

VectorDrop& VectorDrop::operator=(const VectorDrop&vOther)
{
    x = vOther.x; y = vOther.y;
    return *this;
}

//-----------------------------------------------------------------------------
// Array access
//-----------------------------------------------------------------------------

vec_t& VectorDrop::operator[](int i)
{
    return ((vec_t*)this)[i];
}

vec_t VectorDrop::operator[](int i) const
{
    return ((vec_t*)this)[i];
}

//-----------------------------------------------------------------------------
// Base address...
//-----------------------------------------------------------------------------

vec_t* VectorDrop::Base()
{
    return (vec_t*)this;
}

vec_t const* VectorDrop::Base() const
{
    return (vec_t const*)this;
}

//-----------------------------------------------------------------------------
// IsValid?
//-----------------------------------------------------------------------------

bool VectorDrop::IsValid() const
{
    return !isinf(x) && !isinf(y);
}

//-----------------------------------------------------------------------------
// comparison
//-----------------------------------------------------------------------------

bool VectorDrop::operator==(const VectorDrop& src) const
{
    return (src.x == x) && (src.y == y);
}

bool VectorDrop::operator!=(const VectorDrop& src) const
{
    return (src.x != x) || (src.y != y);
}

//-----------------------------------------------------------------------------
// Copy
//-----------------------------------------------------------------------------

void VectorDropCopy(const VectorDrop& src, VectorDrop& dst)
{
    dst.x = src.x;
    dst.y = src.y;
}

void VectorDrop::CopyToArray(float* rgfl) const
{
    rgfl[0] = x; rgfl[1] = y;
}

//-----------------------------------------------------------------------------
// standard Math operations
//-----------------------------------------------------------------------------

void VectorDrop::Negate()
{
    x = -x; y = -y;
}

void VectorDropAdd(const VectorDrop& a, const VectorDrop& b, VectorDrop& c)
{
    c.x = a.x + b.x;
    c.y = a.y + b.y;
}

void VectorDropSubtract(const VectorDrop& a, const VectorDrop& b, VectorDrop& c)
{
    c.x = a.x - b.x;
    c.y = a.y - b.y;
}

void VectorDropMultiply(const VectorDrop& a, vec_t b, VectorDrop& c)
{
    c.x = a.x * b;
    c.y = a.y * b;
}

void VectorDropMultiply(const VectorDrop& a, const VectorDrop& b, VectorDrop& c)
{
    c.x = a.x * b.x;
    c.y = a.y * b.y;
}

void VectorDropDivide(const VectorDrop& a, vec_t b, VectorDrop& c)
{
    vec_t oob = 1.0f / b;
    c.x = a.x * oob;
    c.y = a.y * oob;
}

void VectorDropDivide(const VectorDrop& a, const VectorDrop& b, VectorDrop& c)
{
    c.x = a.x / b.x;
    c.y = a.y / b.y;
}

void VectorDropMA(const VectorDrop& start, float s, const VectorDrop& dir, VectorDrop& result)
{
    result.x = start.x + s * dir.x;
    result.y = start.y + s * dir.y;
}

// FIXME: Remove
// For backwards compatability
void VectorDrop::MulAdd(const VectorDrop& a, const VectorDrop& b, float scalar)
{
    x = a.x + b.x * scalar;
    y = a.y + b.y * scalar;
}

void Vector2DLerp(const VectorDrop& src1, const VectorDrop& src2, vec_t t, VectorDrop& dest)
{
    dest[0] = src1[0] + (src2[0] - src1[0]) * t;
    dest[1] = src1[1] + (src2[1] - src1[1]) * t;
}

//-----------------------------------------------------------------------------
// dot, cross
//-----------------------------------------------------------------------------
vec_t DotProduct2D(const VectorDrop& a, const VectorDrop& b)
{
    return(a.x*b.x + a.y*b.y);
}

// for backwards compatability
vec_t VectorDrop::Dot(const VectorDrop& vOther) const
{
    return DotProduct2D(*this, vOther);
}

vec_t Vector2DNormalize(VectorDrop& v)
{
    vec_t l = v.Length();
    if (l != 0.0f) {
        v /= l;
    }
    else {
        v.x = v.y = 0.0f;
    }
    return l;
}

//-----------------------------------------------------------------------------
// length
//-----------------------------------------------------------------------------
vec_t Vector2DLength(const VectorDrop& v)
{
    return (vec_t)sqrt(v.x*v.x + v.y*v.y);
}

vec_t Vector2DLengthDrop(const VectorDrop& v)
{
    return (vec_t)sqrt(v.x*v.x + v.y*v.y);
}

vec_t VectorDrop::NormalizeInPlace()
{
    return Vector2DNormalize(*this);
}

bool VectorDrop::IsLengthGreaterThan(float val) const
{
    return LengthSqr() > val*val;
}

bool VectorDrop::IsLengthLessThan(float val) const
{
    return LengthSqr() < val*val;
}

vec_t VectorDrop::Length(void) const
{
    return Vector2DLength(*this);
}

vec_t VectorDrop::LengthDrop(void) const
{
    return Vector2DLengthDrop(*this);
}

void Vector2DMin(const VectorDrop&a, const VectorDrop&b, VectorDrop&result)
{
    result.x = (a.x < b.x) ? a.x : b.x;
    result.y = (a.y < b.y) ? a.y : b.y;
}

void Vector2DMax(const VectorDrop&a, const VectorDrop&b, VectorDrop&result)
{
    result.x = (a.x > b.x) ? a.x : b.x;
    result.y = (a.y > b.y) ? a.y : b.y;
}

//-----------------------------------------------------------------------------
// Computes the closest point to vecTarget no farther than flMaxDist from vecStart
//-----------------------------------------------------------------------------
void ComputeClosestPoint2D(const VectorDrop& vecStart, float flMaxDist, const VectorDrop& vecTarget, VectorDrop*pResult)
{
    VectorDrop vecDelta;
    VectorDropSubtract(vecTarget, vecStart, vecDelta);
    float flDistSqr = vecDelta.LengthSqr();
    if (flDistSqr <= flMaxDist * flMaxDist) {
        *pResult = vecTarget;
    }
    else {
        vecDelta /= sqrt(flDistSqr);
        VectorDropMA(vecStart, flMaxDist, vecDelta, *pResult);
    }
}

//-----------------------------------------------------------------------------
// Returns a Vector2D with the min or max in X, Y, and Z.
//-----------------------------------------------------------------------------

VectorDrop VectorDrop::Min(const VectorDrop&vOther) const
{
    return VectorDrop(x < vOther.x ? x : vOther.x, y < vOther.y ? y : vOther.y);
}

VectorDrop VectorDrop::Max(const VectorDrop&vOther) const
{
    return VectorDrop(x > vOther.x ? x : vOther.x, y > vOther.y ? y : vOther.y);
}

//-----------------------------------------------------------------------------
// arithmetic operations
//-----------------------------------------------------------------------------

VectorDrop VectorDrop::operator-(void) const
{
    return VectorDrop(-x, -y);
}

VectorDrop VectorDrop::operator+(const VectorDrop& v) const
{
    VectorDrop res;
    VectorDropAdd(*this, v, res);
    return res;
}

VectorDrop VectorDrop::operator-(const VectorDrop& v) const
{
    VectorDrop res;
    VectorDropSubtract(*this, v, res);
    return res;
}

VectorDrop VectorDrop::operator*(float fl) const
{
    VectorDrop res;
    VectorDropMultiply(*this, fl, res);
    return res;
}

VectorDrop VectorDrop::operator*(const VectorDrop& v) const
{
    VectorDrop res;
    VectorDropMultiply(*this, v, res);
    return res;
}

VectorDrop VectorDrop::operator/(float fl) const
{
    VectorDrop res;
    VectorDropDivide(*this, fl, res);
    return res;
}

VectorDrop VectorDrop::operator/(const VectorDrop& v) const
{
    VectorDrop res;
    VectorDropDivide(*this, v, res);
    return res;
}

VectorDrop operator*(float fl, const VectorDrop& v)
{
    return v * fl;
}

.h

Код:
Expand Collapse Copy
#pragma once

typedef float vec_t;
// 2D Vector
class VectorDrop
{
public:
    // Members
    vec_t x, y, z;
    //float xe, ye, ze;
    // Construction/destruction:
    VectorDrop(void);
    VectorDrop(vec_t X, vec_t Y);
    VectorDrop(vec_t* clr);

    VectorDrop(const VectorDrop&vOther)
    {
        x = vOther.x; y = vOther.y;
    }

    // Initialization
    void Init(vec_t ix = 0.0f, vec_t iy = 0.0f);
    // TODO (Ilya): Should there be an init that takes a single float for consistency?

    // Got any nasty NAN's?
    bool IsValid() const;
    void Invalidate();

    // array access...
    vec_t operator[](int i) const;
    vec_t& operator[](int i);

    // Base address...
    vec_t* Base();
    vec_t const* Base() const;

    // Initialization methods
    void Random(vec_t minVal, vec_t maxVal);
    void Zero(); ///< zero out a vector

                 // equality
    bool operator==(const VectorDrop& v) const;
    bool operator!=(const VectorDrop& v) const;

    // arithmetic operations
    VectorDrop& operator+=(const VectorDrop& v)
    {
        x += v.x; y += v.y;
        return *this;
    }

    VectorDrop& operator-=(const VectorDrop& v)
    {
        x -= v.x; y -= v.y;
        return *this;
    }

    VectorDrop& operator*=(float fl)
    {
        x *= fl;
        y *= fl;
        return *this;
    }

    VectorDrop& operator*=(const VectorDrop& v)
    {
        x *= v.x;
        y *= v.y;
        return *this;
    }

    VectorDrop& operator/=(const VectorDrop& v)
    {
        x /= v.x;
        y /= v.y;
        return *this;
    }

    // this ought to be an opcode.
    VectorDrop& operator+=(float fl)
    {
        x += fl;
        y += fl;
        return *this;
    }

    // this ought to be an opcode.
    VectorDrop& operator/=(float fl)
    {
        x /= fl;
        y /= fl;
        return *this;
    }
    VectorDrop& operator-=(float fl)
    {
        x -= fl;
        y -= fl;
        return *this;
    }

    // negate the vector components
    void Negate();

    // Get the vector's magnitude.
    vec_t Length() const;
    vec_t LengthDrop() const;

    // Get the vector's magnitude squared.
    vec_t LengthSqr(void) const
    {
        return (x*x + y * y);
    }

    // return true if this vector is (0,0,0) within tolerance
    bool IsZero(float tolerance = 0.01f) const
    {
        return (x > -tolerance && x < tolerance &&
            y > -tolerance && y < tolerance);
    }

    vec_t NormalizeInPlace();

    VectorDrop NormalizedDrop() const {
        VectorDrop reses = *this;
        float l = reses.LengthDrop();
        if (l != 0.0f) {
            reses /= l;
        }
        else {
            reses.x = reses.y = reses.z = 0.0f;
        }
        return reses;
    }

    VectorDrop Normalized() const
    {
        return *this / Length();
    }

    bool IsLengthGreaterThan(float val) const;
    bool IsLengthLessThan(float val) const;

    // check if a vector is within the box defined by two other vectors
    bool WithinAABox(VectorDrop const &boxmin, VectorDrop const &boxmax);

    // Get the distance from this vector to the other one.
    //vec_t DistTo(const Vector2D &vOther) const
    //{
    //    Vector delta;

    //    delta.x = x - vOther.x;
    //    delta.y = y - vOther.y;
    //    delta.z = z - vOther.z;

    //    return delta.Length();
    //}

    // Get the distance from this vector to the other one squared.
    // NJS: note, VC wasn't inlining it correctly in several deeply nested inlines due to being an 'out of line' .
    // may be able to tidy this up after switching to VC7
    vec_t DistToDrop(const VectorDrop&vOther) const
    {
        VectorDrop deltar;

        deltar.x = x - vOther.x;
        deltar.y = y - vOther.y;

        return deltar.LengthDrop();
    }

    vec_t DistToSqr(const VectorDrop&vOther) const
    {
        VectorDrop delta;

        delta.x = x - vOther.x;
        delta.y = y - vOther.y;

        return delta.LengthSqr();
    }

    // Copy
    void CopyToArray(float* rgfl) const;

    // Multiply, add, and assign to this (ie: *this = a + b * scalar). This
    // is about 12% faster than the actual vector equation (because it's done per-component
    // rather than per-vector).
    void MulAdd(const VectorDrop& a, const VectorDrop& b, float scalar);

    // Dot product.
    vec_t Dot(const VectorDrop& vOther) const;

    // assignment
    VectorDrop& operator=(const VectorDrop&vOther);

    // 2d
    vec_t Length2D(void) const;
    vec_t Length2DSqr(void) const;

    /// Get the component of this vector parallel to some other given vector
    VectorDrop  ProjectOnto(const VectorDrop& onto);

    // copy constructors
    // Vector2D(const Vector2D &vOther);

    // arithmetic operations
    VectorDrop operator-(void) const;

    VectorDrop operator+(const VectorDrop& v) const;
    VectorDrop operator-(const VectorDrop& v) const;
    VectorDrop operator*(const VectorDrop& v) const;
    VectorDrop operator/(const VectorDrop& v) const;
    VectorDrop operator*(float fl) const;
    VectorDrop operator/(float fl) const;

    // Cross product between two vectors.
    VectorDrop Cross(const VectorDrop&vOther) const;

    // Returns a vector with the min or max in X, Y, and Z.
    VectorDrop Min(const VectorDrop&vOther) const;
    VectorDrop Max(const VectorDrop&vOther) const;
};
Откуда спастил?
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Назад
Сверху Снизу