osg.Vec2ub
是 OpenSceneGraph 中的一个向量类,代表一个由两个 unsigned char
类型组成的向量。
class Vec2ub : public ValueMask<UnsignedByteField, 2, 2>
osg.Vec2ub
提供了以下构造函数:
Vec2ub()
Vec2ub(unsigned char x, unsigned char y)
Vec2ub(const UnsignedByteArray& array)
Vec2ub(const Vec2ub& vec, const ValueMaskBase& mask)
osg.Vec2ub
类有以下成员变量:
unsigned char x
unsigned char y
osg.Vec2ub
类提供了以下成员函数:
void set(unsigned char x, unsigned char y)
unsigned char* ptr()
const unsigned char* ptr() const
unsigned char& operator[](const int i)
unsigned char operator[](const int i) const
bool valid() const
bool isNaN() const
bool isNormalized() const
void normalize()
unsigned int compare(const Vec2ub& rhs) const
float length() const
float length2() const
float normalizeAndGetLength()
Vec2ub operator+(const Vec2ub& rhs) const
Vec2ub operator-(const Vec2ub& rhs) const
Vec2ub operator*(float rhs) const
Vec2ub operator/(float rhs) const
void operator+=(const Vec2ub& rhs)
void operator-=(const Vec2ub& rhs)
void operator*=(float rhs)
void operator/=(float rhs)
bool operator==(const Vec2ub& rhs) const
bool operator!=(const Vec2ub& rhs) const
unsigned char* data()
const unsigned char* data() const
完整的成员函数文档请参考 osg.Vec2ub 官方文档。
#include <osg/Vec2ub>
#include <iostream>
using namespace std;
int main()
{
osg::Vec2ub vec1(100, 200);
osg::Vec2ub vec2(50, 50);
// 计算两个向量的和
osg::Vec2ub sum = vec1 + vec2;
cout << "vec1: " << (int)vec1.x << ", " << (int)vec1.y << endl;
cout << "vec2: " << (int)vec2.x << ", " << (int)vec2.y << endl;
cout << "sum : " << (int)sum.x << ", " << (int)sum.y << endl;
return 0;
}
输出结果:
vec1: 100, 200
vec2: 50, 50
sum : 150, 250