Vector Manual (Classic)

内容表

关于

A vector is a structure composed of three floating-point values. Such a vector is typically used to represent a position in 3D space, a direction, normals, a rotation or a color value.

The vector classes available:

另请参阅 Primitive Data Types Manual (Classic) .

警告
A description of MAXON API vector classes can also be found here: Vectors MAXON API also includes dedicated classes for colors like maxon::Color .
// This example reads the position of the points of the given spline object // and creates null objects at these positions.
const 向量 * const splinePoints = spline->GetPointR(); const Int32 splinePointCount = spline->GetPointCount(); const 矩阵 splineMg = spline->GetMg();
for ( Int i = 0; i < splinePointCount; ++i) { BaseObject * const nullObj = BaseObject::Alloc ( Onull ); if (nullObj && splinePoints) { // get world space position const 向量 worldSpacePoint = splineMg * splinePoints[i]; 矩阵 mg; mg. off = worldSpacePoint; nullObj-> SetMg (mg); doc-> InsertObject (nullObj, nullptr , nullptr ); } else { return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); } }

Access

Vector objects can be created on demand or can be obtained from other entities.

Access 向量 objects stored in a BaseContainer :

另请参阅 BaseContainer Manual .

Access 向量 objects stored in a GeData object ( GeData type is DA_VECTOR ):

另请参阅 GeData Manual .

Vectors are also the building blocks of 矩阵 objects. Especially the off component of a Matrix is often accessed:

另请参阅 Matrix Manual (Classic) .

Vectors are used to represent the position of points of a PointObject like a SplineObject or PolygonObject :

In a GeDialog the float values of three gadgets can be read as a 向量 :

// This example reads the "Size" parameter of the given Cube object. GeData data;

// read "Size" parameter if (cube-> GetParameter ( DescID { PRIM_CUBE_LEN }, data, DESCFLAGS_GET::NONE )) { const 向量 size = data. GetVector (); ApplicationOutput ( "Cube Size: @" _s, size); }

组件

A 向量 is made up of three components, which can be accessed directly:

Alternatively the subscript operator can be used:

// This example reads the color of the given material // and converts the components to integer values. GeData data;

// read "Color" parameter if (mat-> GetParameter ( DescID { MATERIAL_COLOR_COLOR }, data, DESCFLAGS_GET::NONE )) { const 向量 color = data. GetVector ();

// convert to 0 - 255 integer const Int32 colorR = SAFEINT32 (color. x * COLORTOINT_MULTIPLIER ); const Int32 colorG = SAFEINT32 (color. y * COLORTOINT_MULTIPLIER ); const Int32 colorB = SAFEINT32 (color. z * COLORTOINT_MULTIPLIER ); ApplicationOutput ( "Color: @ : @ : @" _s, colorR, colorG, colorB); }

Vector Maths

Vector Properties

Several functions are available to calculate properties of a 向量 object:

// This example compares the distance of one object to two other objects. const 矩阵 mgA = objectA->GetMg(); const 矩阵 mgB = objectB->GetMg(); const 矩阵 mgC = objectC->GetMg(); const 向量 AB = mgB. off - mgA. off ; const 向量 AC = mgC. off - mgA. off ; const Float sqrDistanceAB = AB. GetSquaredLength (); const Float sqrDistanceAC = AC. GetSquaredLength (); const maxon::String objAName { objectA->GetName() }; const maxon::String objBName { objectB->GetName() }; const maxon::String objCName { objectC->GetName() }; if (sqrDistanceAB > sqrDistanceAC) ApplicationOutput ( "Object @ is closer to object @ than object @" _s, objAName, objCName, objBName); else ApplicationOutput ( "Object @ is closer to object @ than object @" _s, objAName, objBName, objCName);

Vector Operators

Basic mathematical operations to handle vectors and vectors with scalars are implemented as operators:

Vector Normalization

// This example normalizes the given vector. const 向量 vec { 10, 20, 30 }; const 向量 normalized = vec. GetNormalized (); ApplicationOutput ( "Vector: @ / Normalized Vector: @" _s, vec, normalized);

Vector Operations

Basic vector based mathematical operations are available as global functions:

注意
To calculate the normal of a polygon use CalcFaceNormal() .
// This example calculates the angle between the given vectors. const 向量 a { 100, 0, 0 }; const 向量 b { 100, 100, 0 }; const Float angle = GetAngle(a, b); const String formattedString = FormatNumber (angle, FORMAT_DEGREE , 0); ApplicationOutput ( "Angle: @" _s, maxon::String { formattedString });

Zero

These functions an be used to check if the components of a vector are zero:

比较

Two vectors can be compared using a dedicated function or the usual operators:

注意
For safe comparison of floating point values see 比较 .

Disc I/O

Vector objects can be stored in a BaseFile HyperFile using:

// This example writes the Vector into a new BaseFile. AutoAlloc<BaseFile> bf; if (bf == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// open BaseFile to write if (bf-> Open (filename, FILEOPEN::WRITE , FILEDIALOG::ANY )) { bf-> WriteVector64 (vector); bf-> 关闭 (); }

// This example reads a Vector from the given BaseFile. AutoAlloc<BaseFile> bf; if (bf == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// open BaseFile to read if (bf-> Open (filename, FILEOPEN::READ , FILEDIALOG::ANY )) { 向量 vector; bf-> ReadVector64 (&vector);

// This example writes the Vector into a new HyperFile. AutoAlloc<HyperFile> hf; if (hf == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// open HyperFile to write if (hf-> Open ( 'vect' , filename, FILEOPEN::WRITE , FILEDIALOG::ANY )) { hf-> WriteVector (vector); hf-> 关闭 (); }

// This example reads a Vector from the given HyperFile. AutoAlloc<HyperFile> hf; if (hf == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );

// open HyperFile to read if (hf-> Open ( 'vect' , filename, FILEOPEN::READ , FILEDIALOG::ANY )) { 向量 vector; hf-> ReadVector (&vector);

另请参阅 BaseFile Manual on 向量 and HyperFile Manual on 向量 .

Utility Functions

Further utility functions are available:

Color Functions

The 向量 class is also used to represent colors in different color spaces:

另请参阅 Color Functions Manual .

延伸阅读

BaseFile::Close
Bool Close()
BaseDocument::InsertObject
void InsertObject(BaseObject *op, BaseObject *parent, BaseObject *pred, Bool checknames=false)
Int
maxon::Int Int
定义: ge_sys_math.h:62
FormatNumber
String FormatNumber(const GeData &val, Int32 format, Int32 fps, Bool bUnit=true)
BaseObject
定义: c4d_baseobject.h:224
maxon::Mat3< maxon::Vector64 >
DescID
定义: lib_description.h:327
FILEDIALOG::ANY
@ ANY
Show an error dialog for any error.
BaseFile::ReadVector64
Bool ReadVector64(Vector64 *v)
Float
maxon::Float Float
定义: ge_sys_math.h:64
Onull
#define Onull
Null.
定义: ge_prepass.h:1009
maxon::String
定义: string.h:1197
BaseObject::SetMg
void SetMg(const Matrix &m)
定义: c4d_baseobject.h:488
FORMAT_DEGREE
@ FORMAT_DEGREE
Floating point with degree sign. Measured in radians, displayed in degrees.
定义: c4d_gui.h:41
SAFEINT32
Int32 SAFEINT32(Float32 x)
定义: apibasemath.h:266
maxon::Vec3::GetSquaredLength
constexpr T GetSquaredLength() const
Returns the squared length of the vector.
定义: vec.h:411
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
BaseFile::Open
Bool Open(const Filename &name, FILEOPEN mode=FILEOPEN::READ, FILEDIALOG error_dialog=FILEDIALOG::IGNOREOPEN, BYTEORDER order=BYTEORDER::V_MOTOROLA, Int32 type='C4DC', Int32 creator='C4D1')
HyperFile::ReadVector
Bool ReadVector(Vector *v)
HyperFile::Open
Bool Open(Int32 ident, const Filename &filename, FILEOPEN mode, FILEDIALOG error_dialog)
maxon::Vec3::z
T z
定义: vec.h:34
String
定义: c4d_string.h:38
FILEOPEN::WRITE
@ WRITE
maxon::Vec3< maxon::Float64, 1 >
maxon::Vec3::x
T x
定义: vec.h:32
maxon::Vec3::GetNormalized
constexpr Unstrided GetNormalized() const
Returns a normalized vector, so that GetLength(vector)==1.0.
定义: vec.h:417
HyperFile::WriteVector
Bool WriteVector(const Vector &v)
maxon::Vec3::y
T y
定义: vec.h:33
GeData
定义: c4d_gedata.h:82
Int32
maxon::Int32 Int32
定义: ge_sys_math.h:58
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
COLORTOINT_MULTIPLIER
static const Float COLORTOINT_MULTIPLIER
Constant to convert from vectors color components to integers.
定义: c4d_tools.h:25
FILEOPEN::READ
@ READ
Open the file for reading.
BaseFile::WriteVector64
Bool WriteVector64(const Vector64 &v)
BaseObject::Alloc
static BaseObject * Alloc(Int32 type)
HyperFile::Close
Bool Close()
maxon::Mat3::off
V off
The translation vector.
定义: matrix.h:279
AutoAlloc
定义: ge_autoptr.h:36
DESCFLAGS_GET::NONE
@ NONE
None.
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)
GeData::GetVector
const Vector & GetVector(void) const
定义: c4d_gedata.h:451

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1