This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Unigine::BoundFrustum Struct

Header: #include <UnigineMathLibBounds.h>

This structure serves to construct the bounding frustum in single precision coordinates.

Notice
Instances of this structure are deleted automatically, when necessary.

In case of double precision coordinates, the bounding frustum should be constructed by using the WorldBoundFrustum structure. It includes the same functions as the BoundFrustum structure, but its functions deal with the double precision coordinates.

Notice
To support both single and double precision builds, you can use the WorldBoundFrustum structure only. The engine will automatically substitute it with the BoundFrustum, if required.

BoundFrustum enables you to check:

  • if the specified bound volume (box, sphere, or other frustum) gets inside the frustum (even partially) - use inside( bound ) methods for this purpose.
  • if the specified bound volume (box, sphere, or other frustum) is inside the frustum completely - use insideAll( bound ) methods for this purpose.
  • if certain points of your object are inside the frustum (may be necessary in case more accurate results are required than the ones obtained using the two methods above) - here you should use inside( point ) methods and check all points of interest.
Notice
Make sure that you use proper aspect-corrected projection for the frustum when necessary. See the picture in the spoiler below: red - default projection matrix, green - aspect-corrected projection matrix.


Usage Example#

For example you can use a BoundFrustum in order to check whether a node is inside the viewing frustum of a camera. Check the component below.

Source code (C++)
#pragma once
#include <UnigineComponentSystem.h>
class FrustumChecker :
	public Unigine::ComponentBase
{
public:
	COMPONENT_DEFINE(FrustumChecker, Unigine::ComponentBase);
	COMPONENT_UPDATE(update);

private:
	void update();
};
Source code (C++)
#include "FrustumChecker.h"
#include "UnigineGame.h"
#include "UnigineMathLibBounds.h"
#include "UnigineVisualizer.h"
REGISTER_COMPONENT(FrustumChecker);

using namespace Unigine;

void FrustumChecker::update()
{	
	// getting the current camera
	Unigine::CameraPtr camera = Game::getPlayer()->getCamera();

	// getting the main window of the application
	Unigine::EngineWindowPtr main_window = WindowManager::getMainWindow();
	if (!main_window) {
		Engine::get()->quit();
		return;
	}
	
	// calculating the current aspect ratio to obtain proper aspect-corrected projection matrix
	// default projection matrix does not take aspect ratio into account
	Unigine::Math::ivec2 main_size = WindowManager::getMainWindow()->getSize();
	float aspect = float(main_size.y) / main_size.x;
	Unigine::Math::mat4 proj = camera->getAspectCorrectedProjection(aspect);
	
	// getting model-view matrix of the camera
	Unigine::Math::mat4 model_view = camera->getModelview();
	Unigine::Math::BoundFrustum bfrustum(proj, model_view);

	// checking if the node's bound gets inside the viewing frustum of the camera
	if (bfrustum.inside(node->getWorldBoundBox())) {
		Log::message("Node's bound is visible inside the frustum.");
		
		// checking whether the bound is completely or partially inside the frustum
		Log::message(bfrustum.insideAll(node->getWorldBoundBox()) ? " COMPLETELY!\n": " PARTIALLY!\n");

		// checking whether a certain point of the object (WorldPosition here) is inside the frustum
		Log::message(bfrustum.inside(node->getWorldPosition()) ? "(The point is INSIDE)\n" : "(The point is OUTSIDE)\n");
	}
	else
		Log::message("Node's bound is outside the frustum.\n");
	
	// displaying node's BoundBox, the Bound Frustum, and a point using the Visualizer
	Visualizer::renderFrustum(proj, Math::inverse(model_view), Math::vec4(1.0f, 0.0f, 0.0f, 1.0f));
	Visualizer::renderBoundBox(node->getBoundBox(), node->getTransform(), Math::vec4(0.0f, 1.0f, 0.0f, 1.0f));
	Visualizer::renderSphere(0.01f, Math::translate(node->getWorldPosition()), Math::vec4(1.0f, 0.0f, 0.0f, 1.0f));
}

BoundFrustum Class

Members


BoundFrustum ( ) #

Constructor. Creates an empty bounding frustum.

static BoundFrustumPtr create ( const mat4& projection, const mat4& modelview ) #

Initialization by the projection and modelview matrices.

Arguments

  • const mat4& projection - Projection matrix.
  • const mat4& modelview - Modelview matrix.

BoundFrustum ( const BoundFrustum & bf ) #

Initialization by the bounding frustum.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

BoundFrustum ( const BoundFrustum& bf, const mat4& itransform ) #

Initialization by the bounding frustum and transformation matrix.

Arguments

  • const BoundFrustum& bf - The bounding frustum.
  • const mat4& itransform - The inverse transformation matrix.

BoundFrustum & operator= ( const BoundFrustum & bf ) #

Assignment operator.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

Return value

Bounding frustum.

void clear ( ) #

Clears the bounding frustum.

void set ( const Math::mat4 & proj ) #

Sets the bounding frustum by the specified projection matrix.

Arguments

  • const Math::mat4 & proj - Projection matrix.

void set ( const Math::mat4 & projection, const Math::mat4 & modelview ) #

Sets the bounding frustum by matrices.

Arguments

  • const Math::mat4 & projection - Projection matrix.
  • const Math::mat4 & modelview - Modelview matrix.

void set ( const BoundFrustum & bf ) #

Sets the bounding frustum by the bounding frustum.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

void set ( const BoundFrustum & bf, const Math::mat4 & itransform ) #

Sets the bounding frustum by the bounding frustum and transformation matrix.

Arguments

  • const BoundFrustum & bf - The bounding frustum.
  • const Math::mat4 & itransform - The inverse transformation matrix.

void setTransform ( const mat4& transform ) #

Sets the current transformation matrix by the specified source transformation matrix.

Arguments

  • const mat4& transform - Source transformation matrix.

void setTransform ( const dmat4& transform ) #

Sets the current transformation matrix by the specified source transformation matrix.

Arguments

  • const dmat4& transform - Source transformation matrix.

void setITransform ( const Math::mat4 & itransform ) #

Sets the current transformation matrix by an inverse transformation matrix.

Arguments

  • const Math::mat4 & itransform - Inverse transformation matrix.

void setITransform ( const Math::dmat4 & itransform ) #

Sets the current transformation matrix by an inverse transformation matrix.

Arguments

  • const Math::dmat4 & itransform - Inverse transformation matrix.

int compare ( const BoundFrustum & bf ) const#

Compares the current bounding frustum with the given one.

Arguments

  • const BoundFrustum & bf - Bounding frustum.

Return value

true if the current bounding frustum is equal to the given one; otherwise, false.

int operator== ( const BoundFrustum & bf ) const#

Bounding frustum equal comparison operator.

Arguments

  • const BoundFrustum & bf - The bounding frustum to compare with.

Return value

true if the current bounding frustum is equal to the given one; otherwise, false.

int operator!= ( const BoundFrustum & bf ) const#

Bounding frustum not equal comparison operator.

Arguments

  • const BoundFrustum & bf - The bounding frustum to compare with.

Return value

true if the current bounding frustum is not equal to the given one; otherwise, false.

bool inside ( const Math::vec3 & point ) const#

Checks if the point is inside the bounding frustum.

Arguments

  • const Math::vec3 & point - The coordinates of the point.

Return value

true if the point is inside the bounding frustum; otherwise, false.

bool inside ( const Math::vec3 & point, float radius ) const#

Checks if the sphere is inside the bounding frustum.

Arguments

  • const Math::vec3 & point - The coordinates of the center of the sphere.
  • float radius - The sphere radius.

Return value

true if the sphere is inside the bounding frustum; otherwise, false.

bool inside ( const Math::vec3 & min, const Math::vec3 & max ) const#

Checks if the box is inside the bounding frustum.

Arguments

  • const Math::vec3 & min - The box minimum coordinate.
  • const Math::vec3 & max - The box maximum coordinate.

Return value

true if the box is inside the bounding frustum; otherwise, false.

bool inside ( const Math::vec3 * points, int num ) const#

Checks if a set of points is inside the bounding frustum.

Arguments

  • const Math::vec3 * points - Vector of points.
  • int num - Number of points.

Return value

true if the points are inside the bounding frustum; otherwise, false.

bool inside ( const BoundSphere & bs ) const#

Checks if the bounding sphere is inside the bounding frustum.

Arguments

Return value

true if the bounding sphere is inside the bounding frustum; otherwise, false.

bool inside ( const BoundBox & bb ) const#

Checks if the bounding box is inside the bounding frustum.

Arguments

Return value

true if the bounding box is inside the bounding frustum; otherwise, false.

bool inside ( const BoundFrustum & bf ) const#

Checks if the specified bounding frustum is inside the current bounding frustum.

Arguments

  • const BoundFrustum & bf - Bounding frustum.

Return value

true if the specified bounding frustum is inside the bounding frustum; otherwise, false.

bool insideFast ( const Math::vec3 & point ) const#

Performs a fast check if the point is inside the bounding frustum.

Arguments

  • const Math::vec3 & point - Point.

Return value

true if the point is inside the bounding frustum; otherwise, false.

bool insideFast ( const Math::vec3 & point, float radius ) const#

Performs a fast check if the sphere is inside the bounding frustum.

Arguments

  • const Math::vec3 & point - Center point.
  • float radius - Radius.

Return value

true if the sphere is inside the bounding frustum; otherwise, false.

bool insideFast ( const Math::vec3 & min, const Math::vec3 & max ) const#

Performs a fast check if the box is inside the bounding frustum.

Arguments

  • const Math::vec3 & min - Minimum point.
  • const Math::vec3 & max - Maximum point.

Return value

true if the box is inside the bounding frustum; otherwise, false.

bool insideFast ( const Math::vec3 * points, int num ) const#

Performs a fast check if the set of points is inside the bounding frustum.

Arguments

  • const Math::vec3 * points - Vector of points.
  • int num - Number of points.

Return value

true if the point is inside the bounding frustum; otherwise, false.

bool insideValid ( const BoundSphere & bs ) const#

Checks if the given bounding sphere is inside the bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding sphere is inside the bounding frustum; otherwise, false.

bool insideValid ( const BoundBox & bb ) const#

Checks if the given bounding box is inside the bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding box is inside the bounding frustum; otherwise, false.

bool insideValid ( const BoundFrustum & bf ) const#

Checks if the given bounding frustum is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

Return value

true if the given bounding frustum is inside the bounding frustum; otherwise, false.

bool insideValidFast ( const BoundSphere & bs ) const#

Performs a fast check if the given bounding sphere is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding sphere is inside the bounding frustum; otherwise, false.

bool insideValidFast ( const BoundBox & bb ) const#

Performs a fast check if the given bounding box is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding box is inside the bounding frustum; otherwise, false.

bool insideValidFast ( const BoundFrustum & bf ) const#

Performs a fast check if the given bounding frustum is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

Return value

true if the given bounding frustum is inside the bounding frustum; otherwise, false.

bool insideAll ( const BoundBox & bb ) const#

Checks if the whole given bounding box is inside the current bounding frustum.

Arguments

Return value

true if the whole bounding box is inside the bounding frustum; otherwise, false.

bool insideAll ( const BoundSphere & bs ) const#

Checks if the whole given bounding sphere is inside the current bounding frustum.

Arguments

Return value

true if the whole bounding sphere is inside the bounding frustum; otherwise, false.

bool insideAll ( const BoundFrustum & bf ) const#

Checks if the whole specified bounding frustum is inside the current bounding frustum.

Arguments

  • const BoundFrustum & bf - Bounding frustum.

Return value

true if the whole specified bounding frustum is inside the current bounding frustum; otherwise, false.

bool insideAllValid ( const BoundSphere & bs ) const#

Checks if the whole given bounding sphere is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding sphere is inside the bounding frustum; otherwise, false.

bool insideAllValid ( const BoundBox & bb ) const#

Checks if the whole given bounding box is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding box is inside the bounding frustum; otherwise, false.

bool insideAllValid ( const BoundFrustum & bf ) const#

Checks if the whole given bounding frustum is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

Return value

true if the given bounding frustum is inside the bounding frustum; otherwise, false.

bool insideAllValidFast ( const BoundSphere & bs ) const#

Performs a fast check if the whole given bounding sphere is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding sphere is inside the bounding frustum; otherwise, false.

bool insideAllValidFast ( const BoundBox & bb ) const#

Performs a fast check if the whole given bounding box is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding box is inside the bounding frustum; otherwise, false.

bool insideAllValidFast ( const BoundFrustum & bf ) const#

Performs a fast check if the whole given bounding frustum is inside the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

Return value

true if the given bounding frustum is inside the bounding frustum; otherwise, false.

bool insidePlanes ( const BoundSphere & bs ) const#

Checks if the given bounding sphere is inside the volume defined by the planes of the current bounding frustum.

Arguments

Return value

true if the given bounding sphere is inside the volume; otherwise, false.

bool insidePlanes ( const BoundBox & bb ) const#

Checks if the given bounding box is inside the volume defined by the planes of the current bounding frustum.

Arguments

Return value

true if the given bounding box is inside the volume; otherwise, false.

bool insidePlanes ( const BoundFrustum & bf ) const#

Checks if the given bounding frustum is inside the volume defined by the planes of the current bounding frustum.

Arguments

  • const BoundFrustum & bf - Bounding frustum.

Return value

true if the given bounding frustum is inside the volume; otherwise, false.

bool insidePlanesValid ( const BoundSphere & bs ) const#

Checks if the given bounding sphere is inside the volume defined by the planes of the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding sphere is inside the volume; otherwise, false.

bool insidePlanesValid ( const BoundBox & bb ) const#

Checks if the given bounding box is inside the volume defined by the planes of the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding box is inside the volume; otherwise, false.

bool insidePlanesValid ( const BoundFrustum & bf ) const#

Checks if the given bounding frustum is inside the volume defined by the planes of the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

Return value

true if the given bounding frustum is inside the volume; otherwise, false.

bool insidePlanesValidFast ( const BoundSphere & bs ) const#

Performs a fast check if the given bounding sphere is inside the volume defined by the planes of the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding sphere is inside the volume; otherwise, false.

bool insidePlanesValidFast ( const BoundBox & bb ) const#

Performs a fast check if the given bounding box is inside the volume defined by the planes of the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

Return value

true if the given bounding box is inside the volume; otherwise, false.

bool insidePlanesValidFast ( const BoundFrustum & bf ) const#

Performs a fast check if the given bounding frustum is inside the volume defined by the planes of the current bounding frustum (assuming that the current bound coordinates are valid).
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

  • const BoundFrustum & bf - The bounding frustum.

Return value

true if the given bounding frustum is inside the volume; otherwise, false.

bool insideShadowValid ( const BoundSphere & object, const Math::vec3 & direction ) const#

Checks if the given bounding sphere is inside the shadow of the current bounding frustum.
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

  • const BoundSphere & object - Bounding sphere.
  • const Math::vec3 & direction - The direction vector.

Return value

true if the given bounding sphere is inside the shadow; otherwise, false.

bool insideShadowValid ( const BoundSphere & object, const BoundSphere & light, const Math::vec3 & offset ) const#

Checks if the given bounding sphere is inside the shadow of the current bounding frustum and outside the bounding sphere of a light source.
Notice
The method doesn't check the status of the current bounding frustum.

Arguments

  • const BoundSphere & object - Bounding sphere.
  • const BoundSphere & light - The bounding sphere of the light source.
  • const Math::vec3 & offset - The offset vector.

Return value

true if the given bounding sphere is inside the shadow and outside the given light source bounding sphere; otherwise, false.

bool isValid ( ) const#

Checks the bounding frustum status.

Return value

true if the bounding frustum is valid, otherwise false.
Last update: 2023-03-04
Build: ()