本文整理汇总了C++中AutoAlloc::GetCoordinate方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoAlloc::GetCoordinate方法的具体用法?C++ AutoAlloc::GetCoordinate怎么用?C++ AutoAlloc::GetCoordinate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoAlloc
的用法示例。
在下文中一共展示了AutoAlloc::GetCoordinate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetVirtualObjects
BaseObject* VoxelGenerator::GetVirtualObjects(BaseObject* op, HierarchyHelp* hh)
{
BaseContainer* data = op->GetDataInstance();
BaseDocument* doc = op->GetDocument();
/************************************************************************/
Bool dirty = op->CheckCache(hh) || op->IsDirty(DIRTYFLAGS_DATA);
if (!dirty)
return op->GetCache(hh);
/************************************************************************/
Float t_scale = data->GetFloat(VGEN_SCALE); if(t_scale == 0.0) return nullptr;
Float t_threshold = data->GetFloat(VGEN_THRESHOLD);
Vector scale(t_scale); //Just the vector version of the uniform scale
/************************************************************************/
//Get the Effex Server (which contains all effex scenes)
FXAPI::FXServer *server = FXAPI::FXServer::Get(doc); if(!server) return nullptr;
//Get the scalar channel's BaseObject interface from the link field
BaseObject* channel_object = op->GetDataInstance()->GetObjectLink(VGEN_CHANNEL, doc); if(!channel_object) return nullptr;
//Find the Effex scene the scalar channel belongs to
FXAPI::FXScene* effex_scene = server->GetEffexScene(channel_object); if(!effex_scene) return nullptr;
//Finally retrieve the scalar channel node from the effex scene */
FXAPI::FXScalarChannel* ptr_channel = static_cast<FXAPI::FXScalarChannel*>(FXAPI::GetNode(effex_scene,channel_object,FXAPI::NodeRetrieveType_ScalarChannel));
if(!ptr_channel) return nullptr;
/************************************************************************/
//We wanna place all voxel cubes under this null object
BaseObject* ret = BaseObject::Alloc(Onull); if(!ret) { return nullptr; }
//Create a reference cube
BaseObject* voxel_cube = BaseObject::Alloc(Ocube); if(!voxel_cube) return ret;
//Set Normal scale
voxel_cube->GetDataInstance()->SetVector(PRIM_CUBE_LEN, Vector(1.0));
//Renaming the cube
voxel_cube->SetName("Voxel Reference");
//Tell the cube to update bounding box etc.
voxel_cube->Message(MSG_UPDATE);
//Finally place the cube under our null object
voxel_cube->InsertUnder(ret);
/************************************************************************/
//Now we create a scalar cell iterator which lets us browse all cells of a scalar channel
//You can use C4D's AutoAlloc class for scope based construction/destruction
//Otherwise just use FXAPI::FXScalarCellIterator::Alloc/Free
AutoAlloc<FXAPI::FXScalarCellIterator> iterator;
//Initialise it with our scalar channel, the cpu threads count we use and if grid border cells should be browsed as well
if(iterator->Init(ptr_channel, 1, true))
{
/************************************************************************/
/* The following part could be called from multiple cpu threads */
/* but here we stay single-threaded */
/************************************************************************/
Int32 cpu_index = 0; //First cpu = 0
//Call once per thread
iterator->Start(cpu_index,false); //passing true would give a reverse iterator
do //Now we browse with a do...while loop all cells of this cpu
{
//The iterator gives us the current cell value
double cell_scalar_value = iterator->GetValue(cpu_index);
//Example: check for value threshold to only create instances in cells containing a value (e.g. smoke density)
if(cell_scalar_value <= t_threshold)
continue; //don't process this cell
//Get the current cell's coordinate (in grid cell space)
NAVIE_GLOBAL::VecInt3D xyz_cell = iterator->GetCoordinate(cpu_index);
//Now convert coordinates from grid cell space to world space coordinates
//which we will use to set the cube instances's position
NAVIE_GLOBAL::vector3d xyz_global;
if(FXAPI::GridToWorld(ptr_channel, xyz_cell, xyz_global, false))
{
//Conversion was fine. Now we create an instance object for this cell
BaseObject* voxel_instance = BaseObject::Alloc(Oinstance); if(!voxel_instance) continue;
//Set the reference voxel cube as source
voxel_instance->GetDataInstance()->SetLink(INSTANCEOBJECT_LINK, voxel_cube);
//Make it a render instance
voxel_instance->GetDataInstance()->SetBool(INSTANCEOBJECT_RENDERINSTANCE, true);
//Renaming the instance to Voxel + its linear coordinate index
voxel_instance->SetName("Voxel Reference" + String::IntToString(iterator->GetLinearCoordinate(cpu_index)));
//Set position (converting from an Effex vector3d to a c4d Vector on the fly)
voxel_instance->SetAbsPos(FXAPI::Vec3DToVector(xyz_global));
//We also control the scale by the scalar cell value
voxel_instance->SetAbsScale(scale * cell_scalar_value);
//Tell the instance to update all its data
voxel_instance->Message(MSG_UPDATE);
//Finally place the instance under our null object
voxel_instance->InsertUnderLast(ret);
}
} while(iterator->SetNext(cpu_index)); //Go to next cell..
//.........这里部分代码省略.........