LVecBase3f

class LVecBase3f

This is the base class for all three-component vectors and points.

Inheritance diagram

Inheritance diagram of LVecBase3f

LVecBase3f(void) = default
LVecBase3f(float fill_value)
LVecBase3f(float x, float y, float z)
explicit LVecBase3f(LVecBase2f const &copy, float z)
LVecBase3f(LVecBase3f const&) = default
std::size_t add_hash(std::size_t hash) const
std::size_t add_hash(std::size_t hash, float threshold) const

Adds the vector into the running hash.

void add_to_cell(int i, float value)

These next functions add to an existing value. i.e. foo.set_x(foo.get_x() + value) These are useful to reduce overhead in scripting languages:

void add_x(float value)
void add_y(float value)
void add_z(float value)
bool almost_equal(LVecBase3f const &other, float threshold) const
bool almost_equal(LVecBase3f const &other) const

Returns true if two vectors are memberwise equal within a specified tolerance.

Returns true if two vectors are memberwise equal within a default tolerance based on the numeric type.

int compare_to(LVecBase3f const &other) const
int compare_to(LVecBase3f const &other, float threshold) const

This flavor of compare_to uses a default threshold value based on the numeric type.

Sorts vectors lexicographically, componentwise. Returns a number less than 0 if this vector sorts before the other one, greater than zero if it sorts after, 0 if they are equivalent (within the indicated tolerance).

void componentwise_mult(LVecBase3f const &other)
LVecBase3f cross(LVecBase3f const &other) const
void cross_into(LVecBase3f const &other)
float dot(LVecBase3f const &other) const
void fill(float fill_value)

Sets each element of the vector to the indicated fill_value. This is particularly useful for initializing to zero.

LVecBase3f fmax(LVecBase3f const &other) const
LVecBase3f fmin(LVecBase3f const &other) const
void generate_hash(ChecksumHashGenerator &hashgen) const
void generate_hash(ChecksumHashGenerator &hashgen, float threshold) const

Adds the vector to the indicated hash generator.

float get_cell(int i) const
static TypeHandle get_class_type(void)
float const *get_data(void) const

Returns the address of the first of the three data elements in the vector. The remaining elements occupy the next positions consecutively in memory.

std::size_t get_hash(void) const
std::size_t get_hash(float threshold) const

Returns a suitable hash for phash_map.

static constexpr int get_num_components(void)
LVecBase3f get_standardized_hpr(void) const

Try to un-spin the hpr to a standard form. Like all standards, someone decides between many arbitrary possible standards. This function assumes that 0 and 360 are the same, as is 720 and -360. Also 180 and -180 are the same. Another example is -90 and 270. Each element will be in the range -180.0 to 179.99999. The original usage of this function is for human readable output.

It doesn’t work so well for asserting that foo_hpr is roughly equal to bar_hpr. Try using LQuaternionf::is_same_direction() for that. See Also: get_standardized_rotation, LQuaternion::is_same_direction

float get_x(void) const
LVecBase2f get_xy(void) const

Returns a 2-component vector that shares just the first two components of this vector.

LVecBase2f get_xz(void) const

Returns a 2-component vector that shares just the first and last components of this vector.

float get_y(void) const
LVecBase2f get_yz(void) const

Returns a 2-component vector that shares just the last two components of this vector.

float get_z(void) const
bool is_nan(void) const

Returns true if any component of the vector is not-a-number, false otherwise.

float length(void) const

Returns the length of the vector, by the Pythagorean theorem.

float length_squared(void) const

Returns the square of the vector’s length, cheap and easy.

bool normalize(void)

Normalizes the vector in place. Returns true if the vector was normalized, false if it was a zero-length vector.

LVecBase3f normalized(void) const

Normalizes the vector and returns the normalized vector as a copy. If the vector was a zero-length vector, a zero length vector will be returned.

void output(std::ostream &out) const
LVecBase3f project(LVecBase3f const &onto) const

Returns a new vector representing the projection of this vector onto another one. The resulting vector will be a scalar multiple of onto.

void read_datagram(DatagramIterator &source)

Reads the vector from the Datagram using get_stdfloat().

void read_datagram_fixed(DatagramIterator &source)

Reads the vector from the Datagram using get_float32() or get_float64(). See write_datagram_fixed().

void set(float x, float y, float z)
void set_cell(int i, float value)
void set_x(float value)
void set_y(float value)
void set_z(float value)
static constexpr int size(void)
LVecBase3f const &unit_x(void)

Returns a unit X vector.

LVecBase3f const &unit_y(void)

Returns a unit Y vector.

LVecBase3f const &unit_z(void)

Returns a unit Z vector.

bool validate_ptr(void const *ptr)
void write_datagram(Datagram &destination) const

Writes the vector to the Datagram using add_stdfloat(). This is appropriate when you want to write the vector using the standard width setting, especially when you are writing a bam file.

void write_datagram_fixed(Datagram &destination) const

Writes the vector to the Datagram using add_float32() or add_float64(), depending on the type of floats in the vector, regardless of the setting of Datagram::set_stdfloat_double(). This is appropriate when you want to write a fixed-width value to the datagram, especially when you are not writing a bam file.

LVecBase3f const &zero(void)

Returns a zero-length vector.