本文整理汇总了C++中Spatial类的典型用法代码示例。如果您正苦于以下问题:C++ Spatial类的具体用法?C++ Spatial怎么用?C++ Spatial使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Spatial类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: orientation
//----------------------------------------------------------------------------
void NodeBillboard::UpdateWorldData(Double appTime, Bool updateControllers)
{
// Compute billboard's world transforms based on its parent's world
// transform and its local transforms. Notice that you should not call
// Node::UpdateWorldData since that function updates its children. The
// children of a NodeBillboard cannot be updated until the billboard is
// aligned with the camera.
Spatial::UpdateWorldData(appTime, updateControllers);
if (mspCamera)
{
// Inverse-transform the camera to the model space of the billboard.
Vector3F camLocation = World.ApplyInverse(mspCamera->GetLocation());
// To align the billboard, the projection of the camera to the
// xz-plane of the billboard's model space determines the angle of
// rotation about the billboard's model y-axis. If the projected
// camera is on the model axis (x = 0 and z = 0), ATan2 returns zero
// (rather than NaN), so there is no need to trap this degenerate
// case and handle it separately.
Float angle = MathF::ATan2(camLocation.X(), camLocation.Z());
Matrix34F orientation(Vector3F::UNIT_Y, angle);
World.SetRotate(World.GetMatrix() * orientation);
}
// update the children now that the billboard orientation is known
for (UInt i = 0; i < mChildren.GetQuantity(); i++)
{
Spatial* pChild = mChildren[i];
if (pChild)
{
pChild->UpdateGS(appTime, false, updateControllers);
}
}
}
示例2: GetVisibleSetRenderObject
//----------------------------------------------------------------------------
void Node::GetVisibleSet(Culler& rCuller, Bool noCull)
{
for (UInt i = 0; i < mEffects.GetQuantity(); i++)
{
// This is a global effect. Place a 'begin' marker in the visible
// set to indicate the effect is active.
rCuller.Insert(mEffects[i], NULL);
}
GetVisibleSetRenderObject(rCuller, noCull);
// All RenderObjects in the subtree are added to the visible set. If
// a global effect is active, the RenderObjects in the subtree will be
// drawn using it.
for (UInt i = 0; i < mChildren.GetQuantity(); i++)
{
Spatial* pChild = mChildren[i];
if (pChild)
{
pChild->OnGetVisibleSet(rCuller, noCull);
}
}
for (UInt i = 0; i < mEffects.GetQuantity(); i++)
{
// Place an 'end' marker in the visible set to indicate that the
// global effect is inactive.
rCuller.Insert(NULL, NULL);
}
}
示例3: get
/* ------------------------------------------------------- */
Object* SceneGraph::get(const String& root, const String& name)
{
Spatial* s = m_roots->get(root);
if (!s)
throw new Exception("root object not found in scene graph");
return s->getObject(name);
}
示例4: switch
void NavigationMeshInstance::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
Spatial *c = this;
while (c) {
navigation = c->cast_to<Navigation>();
if (navigation) {
if (enabled && navmesh.is_valid()) {
nav_id = navigation->navmesh_create(navmesh, get_relative_transform(navigation), this);
}
break;
}
c = c->get_parent_spatial();
}
if (navmesh.is_valid() && get_tree()->is_debugging_navigation_hint()) {
MeshInstance *dm = memnew(MeshInstance);
dm->set_mesh(navmesh->get_debug_mesh());
if (is_enabled()) {
dm->set_material_override(get_tree()->get_debug_navigation_material());
} else {
dm->set_material_override(get_tree()->get_debug_navigation_disabled_material());
}
add_child(dm);
debug_view = dm;
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
if (navigation && nav_id != -1) {
navigation->navmesh_set_transform(nav_id, get_relative_transform(navigation));
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (navigation) {
if (nav_id != -1) {
navigation->navmesh_remove(nav_id);
nav_id = -1;
}
}
if (debug_view) {
debug_view->queue_delete();
debug_view = NULL;
}
navigation = NULL;
} break;
}
}
示例5: motion_delta
void SpringArm::process_spring() {
// From
real_t motion_delta(1);
real_t motion_delta_unsafe(1);
Vector3 motion;
const Vector3 cast_direction(get_global_transform().basis.xform(Vector3(0, 0, 1)));
if (shape.is_null()) {
motion = Vector3(cast_direction * (spring_length));
PhysicsDirectSpaceState::RayResult r;
bool intersected = get_world()->get_direct_space_state()->intersect_ray(get_global_transform().origin, get_global_transform().origin + motion, r, excluded_objects, mask);
if (intersected) {
float dist = get_global_transform().origin.distance_to(r.position);
dist -= margin;
motion_delta = dist / (spring_length);
}
} else {
motion = Vector3(cast_direction * spring_length);
get_world()->get_direct_space_state()->cast_motion(shape->get_rid(), get_global_transform(), motion, 0, motion_delta, motion_delta_unsafe, excluded_objects, mask);
}
current_spring_length = spring_length * motion_delta;
Transform childs_transform;
childs_transform.origin = get_global_transform().origin + cast_direction * (spring_length * motion_delta);
for (int i = get_child_count() - 1; 0 <= i; --i) {
Spatial *child = Object::cast_to<Spatial>(get_child(i));
if (child) {
childs_transform.basis = child->get_global_transform().basis;
child->set_global_transform(childs_transform);
}
}
}
示例6: _propagate_exit_world
void Viewport::_propagate_exit_world(Node *p_node) {
if (p_node!=this) {
if (!p_node->is_inside_scene()) //may have exited scene already
return;
Spatial *s = p_node->cast_to<Spatial>();
if (s) {
s->notification(Spatial::NOTIFICATION_EXIT_WORLD,false);
} else {
Viewport *v = p_node->cast_to<Viewport>();
if (v) {
if (v->world.is_valid())
return;
}
}
}
for(int i=0;i<p_node->get_child_count();i++) {
_propagate_exit_world(p_node->get_child(i));
}
}
示例7: _parse_obj
Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
List<Ref<Mesh> > meshes;
Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, Vector3(1, 1, 1), r_missing_deps);
if (err != OK) {
if (r_err) {
*r_err = err;
}
return NULL;
}
Spatial *scene = memnew(Spatial);
for (List<Ref<Mesh> >::Element *E = meshes.front(); E; E = E->next()) {
MeshInstance *mi = memnew(MeshInstance);
mi->set_mesh(E->get());
mi->set_name(E->get()->get_name());
scene->add_child(mi);
mi->set_owner(scene);
}
if (r_err) {
*r_err = OK;
}
return scene;
}
示例8: lightGray
//----------------------------------------------------------------------------
void Delaunay3D::DoSearch ()
{
// Make all tetra wireframe.
const int numSimplices = mDelaunay->GetNumSimplices();
Float4 lightGray(0.75f, 0.75f, 0.75f, 1.0f);
int i;
for (i = 0; i < numSimplices; ++i)
{
ChangeTetraStatus(i, lightGray, true);
}
// Generate random point in AABB of data set.
Vector3f random;
random.X() = Mathf::IntervalRandom(mMin.X(), mMax.X());
random.Y() = Mathf::IntervalRandom(mMin.Y(), mMax.Y());
random.Z() = Mathf::IntervalRandom(mMin.Z(), mMax.Z());
// Move sphere to this location.
Spatial* sphere = mScene->GetChild(0);
sphere->Culling = Spatial::CULL_DYNAMIC;
sphere->LocalTransform.SetTranslate(random);
sphere->Update();
if (mDelaunay->GetContainingTetrahedron(random) >= 0)
{
// Make all tetra on the path solid.
const int pathLast = mDelaunay->GetPathLast();
for (i = 0; i <= pathLast; ++i)
{
int index = mDelaunay->GetPath()[i];
float red, blue;
if (pathLast > 0)
{
red = i/(float)pathLast;
blue = 1.0f - red;
}
else
{
red = 1.0f;
blue = 0.0f;
}
ChangeTetraStatus(index, Float4(red, 0.0f, blue, 0.5f), false);
}
}
else
{
// The point is outside the convex hull. Change the wireframe
// color for the last visited face in the search path.
int index = mDelaunay->GetPath()[mDelaunay->GetPathLast()];
int v0, v1, v2, v3;
int vOpposite = mDelaunay->GetLastFace(v0, v1, v2, v3);
ChangeLastTetraStatus(index, vOpposite,
Float4(0.0f, 1.0f, 0.0f, 0.5f),
Float4(0.0f, 0.25f, 0.0f, 0.5f));
}
mCuller.ComputeVisibleSet(mScene);
}
示例9: importer
//----------------------------------------------------------------------------
Node* Game::LoadAndInitializeScene()
{
Importer importer("Data/Scene/");
Node* pScene = importer.LoadSceneFromXml("Scene.xml", mspPhysicsWorld);
if (!pScene)
{
return NULL;
}
NodeCamera* pCameraNode = pScene->FindChild<NodeCamera>();
WIRE_ASSERT(pCameraNode /* No Camera in scene.xml */);
mspSceneCamera = pCameraNode->Get();
mSortingCuller.SetCamera(mspSceneCamera);
// The maximum number of objects that are going to be culled is the
// number of objects we imported. If we don't set the size of the set now,
// the culler will dynamically increase it during runtime. This is not
// a big deal, however it is better to avoid memory allocations during the
// render loop.
UInt renderObjectCount = importer.GetStatistics()->RenderObjectCount;
mSortingCuller.SetMaxQuantity(renderObjectCount);
// Create and configure probe robot controller
SpatialPtr spRedHealthBar = mspGUI->FindChild("RedHealthBar");
WIRE_ASSERT(spRedHealthBar /* No RedHealthBar in GUI.xml */);
Node* pProbeRobotSpatial = DynamicCast<Node>(pScene->FindChild("Probe Robot"));
WIRE_ASSERT(pProbeRobotSpatial /* No Probe Robot in Scene.xml */);
// Detach red energy/health bar and attach it robot probe as a billboard
NodeBillboard* pBillboard = WIRE_NEW NodeBillboard;
pProbeRobotSpatial->AttachChild(pBillboard);
Node* pParent = DynamicCast<Node>(spRedHealthBar->GetParent());
WIRE_ASSERT(pParent);
pParent->DetachChild(spRedHealthBar);
pBillboard->AttachChild(spRedHealthBar);
Spatial* pPlayerSpatial = pScene->FindChild("Player");
WIRE_ASSERT(pPlayerSpatial /* No Player in Scene.xml */);
mspProbeRobot = WIRE_NEW ProbeRobot(mspPhysicsWorld, pPlayerSpatial,
spRedHealthBar);
pProbeRobotSpatial->AttachController(mspProbeRobot);
// Create and configure player controller
mspPlayer = WIRE_NEW Player(mspSceneCamera, mspPhysicsWorld);
pPlayerSpatial->AttachController(mspPlayer);
Spatial* pPlatform = pScene->FindChild("Platform");
WIRE_ASSERT(pPlatform /* Platform object missing in scene */);
pPlatform->AttachController(WIRE_NEW Elevator(mspPhysicsWorld));
pScene->Bind(GetRenderer());
pScene->WarmUpRendering(GetRenderer());
return pScene;
}
示例10: main
int main() {
Compass testCompass;
InterfaceKit ifKit;
LCD lcd;
Motor motor;
Spatial spatial;
CPhidgetManagerHandle device = 0;
LocalErrorCatcher(
CPhidgetManager_create(&device));
LocalErrorCatcher(
CPhidgetManager_set_OnAttach_Handler((CPhidgetManagerHandle) device,
AttachHandler, NULL));
LocalErrorCatcher(
CPhidgetManager_set_OnDetach_Handler((CPhidgetManagerHandle ) device,
DetachHandler, NULL));
LocalErrorCatcher(
CPhidgetManager_set_OnError_Handler((CPhidgetManagerHandle) device,
LibraryErrorHandler, NULL));
printf("Starting Phidget Playground...\n");
// Most opening and closing would be via a cast to
// (CPhidgetHandle), however, this manager has its
// own handle struct to cast to.
LocalErrorCatcher(
CPhidgetManager_open((CPhidgetManagerHandle) device));
std::stringstream ss;
lcd.clear();
for(int i=0;i<1000;i++){
testCompass.refresh();
ss << std::fixed << std::setprecision(1) << "Heading: " << testCompass.getHeading();
lcd.setText(ss.str(), 0);
ss.str(std::string());
ss << std::fixed << std::setprecision(2) << spatial.getAcceleration(AXIS_X) << " " << spatial.getAcceleration(AXIS_Y) << " " << spatial.getAcceleration(AXIS_Z);
lcd.setText(ss.str(), 1);
ss.str(std::string());
usleep(100000);
}
printf("Press Enter to end...\n");
getchar();
LocalErrorCatcher(
CPhidgetManager_close((CPhidgetManagerHandle) device));
LocalErrorCatcher(
CPhidgetManager_delete((CPhidgetManagerHandle) device));
return 0;
}
示例11: switch
void VisualInstance::_notification(int p_what) {
switch(p_what) {
case NOTIFICATION_ENTER_WORLD: {
// CHECK ROOM
Spatial * parent = get_parent_spatial();
Room *room=NULL;
bool is_geom = cast_to<GeometryInstance>();
while(parent) {
room = parent->cast_to<Room>();
if (room)
break;
if (is_geom && parent->cast_to<BakedLightSampler>()) {
VS::get_singleton()->instance_geometry_set_baked_light_sampler(get_instance(),parent->cast_to<BakedLightSampler>()->get_instance());
break;
}
parent=parent->get_parent_spatial();
}
if (room) {
VisualServer::get_singleton()->instance_set_room(instance,room->get_instance());
}
// CHECK SKELETON => moving skeleton attaching logic to MeshInstance
/*
Skeleton *skeleton=get_parent()?get_parent()->cast_to<Skeleton>():NULL;
if (skeleton)
VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() );
*/
VisualServer::get_singleton()->instance_set_scenario( instance, get_world()->get_scenario() );
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
Transform gt = get_global_transform();
VisualServer::get_singleton()->instance_set_transform(instance,gt);
} break;
case NOTIFICATION_EXIT_WORLD: {
VisualServer::get_singleton()->instance_set_scenario( instance, RID() );
VisualServer::get_singleton()->instance_set_room(instance,RID());
VisualServer::get_singleton()->instance_attach_skeleton( instance, RID() );
VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() );
} break;
}
}
示例12: switch
void GridMap::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
Spatial *c = this;
while (c) {
navigation = Object::cast_to<Navigation>(c);
if (navigation) {
break;
}
c = Object::cast_to<Spatial>(c->get_parent());
}
last_transform = get_global_transform();
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
_octant_enter_world(E->key());
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
Transform new_xform = get_global_transform();
if (new_xform == last_transform)
break;
//update run
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
_octant_transform(E->key());
}
last_transform = new_xform;
} break;
case NOTIFICATION_EXIT_WORLD: {
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
_octant_exit_world(E->key());
}
navigation = NULL;
//_queue_octants_dirty(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS);
//_update_octants_callback();
//_update_area_instances();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
_update_visibility();
} break;
}
}
示例13: UpdateState
//----------------------------------------------------------------------------
void Node::UpdateState (TStack<GlobalState*>* akGStack,
TStack<Light*>* pkLStack)
{
for (int i = 0; i < m_kChild.GetQuantity(); i++)
{
Spatial* pkChild = m_kChild[i];
if (pkChild)
{
pkChild->UpdateRS(akGStack,pkLStack);
}
}
}
示例14: _AddEntity
void SceneAsset::_AddEntity(Entity* entity) {
sceneEntities.push_back(Bind(entity));
if (cullingSystem) {
Spatial* s = entity->GetSpatial();
bool isCamera = (Component::GetComponentCatagory(s->GetClassID()) & Camera::Traits::GetCatagory()) == Camera::Traits::GetCatagory();
if (s) {
if (!isCamera)
cullingSystem->AddBody(s);
s->_SetCullingSystem(cullingSystem);
}
}
}
示例15: UpdateWorldTransform
void Spatial::GeometricStateUpdate()
{
UpdateWorldTransform();
//Propogate World Bounds To Root {
Spatial * parent = GetParentAs<Spatial>();
while (parent != NULL)
{
parent->UpdateWorldBound();
parent = parent->GetParentAs<Spatial>();
}
//Propogate World Bounds To Root }
}