osg.Vec2us
是OpenSceneGraph中用于表示二维无符号短整型向量的类。二维无符号短整型向量包含两个成员变量:x
和 y
,分别表示向量在x轴和y轴上的分量。
osg.Vec2us()
:创建一个初始值为0的二维无符号短整型向量。
osg.Vec2us(unsigned short _x, unsigned short _y)
:基于给定的x和y值创建一个二维无符号短整型向量。
void set(unsigned short _x, unsigned short _y)
:设置向量的x和y值。
unsigned short *ptr()
:返回指向向量起始地址的指针。
const unsigned short *ptr() const
:返回指向向量起始地址的const指针。
void zero()
:将向量的x和y值设置为0。
void negate()
:将向量的x和y值取反。
float length() const
:返回向量的长度。
float length2() const
:返回向量的长度的平方。
void normalize()
:将向量归一化。
osg.Vec2us operator+(const osg.Vec2us &rhs) const
:返回与另一个向量相加的结果向量。
osg.Vec2us operator-(const osg.Vec2us &rhs) const
:返回与另一个向量相减的结果向量。
osg.Vec2us operator*(float rhs) const
:返回与标量乘积的结果向量。
osg.Vec2us operator/(float rhs) const
:返回与标量除积的结果向量。
unsigned short & operator[](int i)
:返回向量的第i个成员变量的引用。
const unsigned short & operator[](int i) const
:返回向量的第i个成员变量的const引用。
bool operator==(const osg.Vec2us &rhs) const
:检查向量是否与另一个向量相等。
bool operator!=(const osg.Vec2us &rhs) const
:检查向量是否与另一个向量不相等。
bool operator<(const osg.Vec2us &rhs) const
:按字典序比较向量和另一个向量。
static const osg.Vec2us & zero()
:返回一个零向量的静态实例。unsigned short x
:向量在x轴上的分量。
unsigned short y
:向量在y轴上的分量。
#include <iostream>
#include <osg/Vec2us>
int main() {
osg::Vec2us v(2, 5);
std::cout << "v = (" << v.x << ", " << v.y << ")" << std::endl;
osg::Vec2us w = v + osg::Vec2us(3, 1);
std::cout << "w = (" << w[0] << ", " << w[1] << ")" << std::endl;
float len = w.length();
std::cout << "Length of w: " << len << std::endl;
return 0;
}
输出:
v = (2, 5)
w = (5, 6)
Length of w: 7.07107