WVR_CreateSpatialAnchor¶
-
WVR_EXPORT WVR_Result WVR_CreateSpatialAnchor(const WVR_SpatialAnchorCreateInfo * createInfo, WVR_SpatialAnchor * anchor)
Function is used to create a spatial anchor.
Developers use this API to create a spatial anchor and get an anchor handle. This spatial anchor will be cleared once AP session closed.
Note: Since API Level 14, once the spatial anchor list has been changed, the corresponding event (WVR_EventType) will be fired. This API will cause WVR_EventType_SpatialAnchor_Changed event.
- Version
- API Level 11
- Parameters
createInfo
: creation information, refer to WVR_SpatialAnchorCreateInfoanchor
: returned handle object that holds the spatial anchor is related to createInfo
- Return Value
WVR_Success
: Create a spatial anchor successfully.others
: WVR_Result mean failure.
WVR_SpatialAnchor handle¶
#define WVR_DEFINE_HANDLE(object) typedef uint64_t object;
WVR_DEFINE_HANDLE(WVR_SpatialAnchor)
The handle is created by WVR_CreateSpatialAnchor. This handle is an object that allows an application to communicate with VIVE Wave™ runtime.
How to use¶
Sample function:
#include <wvr/wvr_scene.h>
#include <wvr/wvr_anchor.h>
WVR_Pose_t wvrPose = {1, 2, 3, 1.0, 2.2, 3.3, 4.4};
WVR_SpatialAnchorCreateInfo info = {wvrPose, WVR_PoseOriginModel_OriginOnGround, "sampleAnchor"};
WVR_SpatialAnchor anchor;
if (WVR_CreateSpatialAnchor(&info, &anchor) == WVR_Success) {
// create anchor successfully
}
// somewhere to listen spatial anchor list change event
void ProcessEvent() {
WVR_Event_t event;
while(WVR_PollEventQueue(&event)) {
switch (event.common.type) {
case WVR_EventType_SpatialAnchor_Changed: {
uint32_t output = 0;
if (WVR_EnumerateSpatialAnchors(0, &output, nullptr) == WVR_Success) {
auto anchors = (WVR_SpatialAnchor*)malloc(sizeof(WVR_SpatialAnchor)*(output));
if (WVR_EnumerateSpatialAnchors(output, &output, anchors) == WVR_Success) {
// enumerate all spatial anchors successfully
}
}
break;
}
}
}
}