This wiki is intended for older versions of Motive. For the latest documentation, please refer to
docs.optitrack.com

NatNet: Class/Function Reference

Warning2.png

THIS PAGE IS UNDER CONSTRUCTION THIS PAGE IS UNDER CONSTRUCTION THIS PAGE IS UNDER CONSTRUCTION THIS PAGE IS UNDER CONSTRUCTION THIS PAGE IS UNDER CONSTRUCTION THIS PAGE IS UNDER CONSTRUCTION THIS PAGE IS UNDER CONSTRUCTION THIS PAGE IS UNDER CONSTRUCTION

NatNet: Class/Function Reference is under development. It will be available soon. Thank you for your patience!



Back to the NatNet SDK page



This page provides function and class references of the NatNet SDK library.

The NatNetClient class (or NatNetClientML from the managed assembly) is the key object of the SDK. An instance of this client class allows an application to connect to a server application and query data. For additional information, refer to the provided headers files (native) or reference the NatNatML.dll file (managed).


Note:

  • NatNet SDK is backwards compatible. Deprecated methods from previous SDK versions are not listed on this page but they are still supported.
  • Note that some parts of the managed .NET assembly may be slightly different from the native library reference provided here. Refer to the NatNetML.dll file using an object browser for detailed information.


ErrorCode


Most of the NatNet SDK functions return their operation results in an integer type representation named ErrorCode, which is just an enumerator that describes operation results as the following:

Error Name Integer Description
ErrorCode_OK 0 Operation successful
ErrorCode_Internal 1 Suspect internal errors. Contact support.
ErrorCode_External 2 External errors. Make sure correct parameters are used for input arguments when calling the methods.
ErrorCode_Network 3 The error occurred on the network side.
ErrorCode_Other 4 Unlisted error is conflicting the method call.


NatNetClient Class


The NatNetClient class is the main component of the NatNet SDK. Using an instance of the NatNetClient class, you can establish a network connection with a server application (e.g. Motive) and query data descriptions, tracking data, and send/receive remote commands. For detailed declarations, refer to the NatNetClient.h header file included in the SDK.


Constructor and Destructor

NatNetClient::NatNetClient()

Constructor: Creates a new instance of a NatNetClient class. Defaults to multicast connection if no input is given.


NatNetClient::NatNetClient(iConnectionType)

Constructor: Creates a new instance of a NatNet Client using the specified connection protocol; either unicast or multicast.

Input: iConnectionType: (0 = Multicast, 1 = Unicast).


NatNetClient::~NatNetClient()

Destructor: Destructor


Member Methods

NatNetClient::Initialize

int   Initialize( const char* szLocalAddress, const char* szServerAddress );
int   Initialize( const char* szLocalAddress, const char* szServerAddress,
			   int hostCommandPort=0, const char* szMulticastAddress = 0 );
Description
This method connects an instantiated NatNetClient object to a server application (e.g. Motive) at the inputted IP address.
Input Parameters:
  • Local address. IP address of the localhost where the client application is running.
  • Server address. IP address where the server application is streaming to.
  • (Optional) Command port. Defaults to 1510.
  • (Optional) Data port. Defaults to 1511.
  • (Optional) Multicast IP address. Defaults to 239.255.42.99:1511.
Returns:
ErrorCode, On success, it returns 0.


NatNetClient::Uninitialize

int   Uninitialize();
Description
Calling this method disconnects the client from the Motive server application.
Input Parameters:
  • None
Returns:
ErrorCode, On success, it returns 0 or ErrorCode_OK.


NatNetClient::GetServerDescription

int   GetServerDescription( sServerDescription* pServerDescription );
Description
Requests a description of the current NatNet server that a client object is connected to and saves it into an instance of sServerDescription. This call is blocked until the request is responded or times out.
Input Parameters:
  • Declared sServerDescription object.
Returns:
ErrorCode, On success, it returns 0 or ErrorCode_OK.


NatNetClient::SetDataCallback

int   SetDataCallback(void (*CallbackFunction)(sFrameOfMocapData* pFrameOfData, void* pUserData), 
                                                                              void* pUserData=0);
Description

This method sets a frame handler function and creates a new thread for receiving and processing each frame of capture data.

  • Managed Assembly: Use OnFrameReady event type to add a function delegate.
Input Parameters:
  • CallbackFunction: Afunction for handling each incoming frame of tracking data. Format of the inputted function must agree with the declared input argument. For example:
void __cdecl DataHandler(sFrameOfMocapData* data, void* pUserData);
  • User definable data: the Client object.
Returns:
ErrorCode, On success, it returns 0 or ErrorCode_OK.


NatNetClient::SendMessageAndWait

int   SendMessageAndWait( const char* szRequest,
			   void** ppServerResponse, 
			   int* pResponseSize );
int   SendMessageAndWait( const char* szRequest,
			   int tries, int timeout, 
			   void** ppServerResponse,
			   int* pResponseSize );
Description
Sends a remote command to the NatNet server and waits for a response. See NatNet: Remote Requests/Commands for more details.
Input Parameters:
  • szRequest: NatNet command.
  • (Optional) tries: Number of attempts to send the command. Default: 10.
  • (Optional) timeout: Number of milliseconds to wait for a response from the server before the call times out. Default: 20.
  • ppServerResponse: Application defined response.
  • pResponseSize: Number of bytes in response
Returns:
ErrorCode, On success, it returns 0 or ErrorCode_OK.


NatNetClient::NatNetVersion

void   NatNetVersion( unsigned char outVersion[4] );
Description
This function gets the version (#.#.#.#) of the NatNet SDK and saves it into an array.
Input Parameters:
  • Unsigned char array with a array length of 4.
Returns:
  • Void


NatNetClient::SendMessageCallback

int SetMessageCallback(void (*CallbackFunction)(int id, char *szTraceMessage));
Description
This function assignes a callback handler function for receiving and reporting error/debug messages.
Input Parameters:
  • CallbackFunction: A function for handling the log messages that are sent out from the server application. Format of the linked function must agree with the input argument. For example:
void __cdecl MessageHandler(int msgType, char* msg);
Returns:
  • Void


NatNetClient::DecodeID

void   DecodeID( int compositeId,
		  int* pOutEntityId,
		  int* pOutMemberId );
Description
Takes an ID of a data set (a marker, a rigid body, a skeleton, or a force plate), and decodes its model ID and member ID into the provided integer variables. For example, ID of a skeleton bone segment will be decoded into its model ID (skeleton) and rigid body ID (bone). See NatNet: Data Types.
Input Parameters:
  • An ID value for a respective data set (sRigidBodyData, sSkeletonData, sMarker, or sFrocePLateData) from a sFrameOfMocapData packet.
  • Pointer to declared integer value for saving the entity ID and the member ID (e.g. Skeleton ID and its bone rigid body ID).
Returns:
  • Void


NatNetClient::DecodeTimecode

bool   DecodeTimecode(unsigned int inTimecode, unsigned int inTimecodeSubframe,
			int* hour, int* minute, int* second, int* frame, int* subframe);
Description
Helper function to decode OptiTrack timecode data into individual components.
Input Parameters:
  • Timecode integer from a packet of sFrameOfMocapData. (timecode)
  • TimecodeSubframe integer from a packet of sFrameOfMocapData. (timecodeSubframe)
  • Pointers to declared integer variables for saving the hours (pOutHour), minutes (pOutMinute), seconds (pOutSecond), frames (pOutFrame), and subframes (pOutSubframe) values.
Returns:
  • ErrorCode, On success, it returns 0 or ErrorCode_OK.


NatNetClient::TimecodeStringify

bool	DecodeTimecode( unsigned int inTimecode, 
			unsigned int inTimecodeSubframe,
			char* Buffer,
			int BufferSize );
Description
Helper function to parse OptiTrack timecode into a user friendly string in the form hh:mm:ss:ff:yy
Input Parameters:
  • inTimecode: Timecode integer from a packet of sFrameOfMocapData.
  • inTimecodeSubframe: TimecodeSubframe integer from a packet of sFrameOfMocapData.
  • Buffer: Declared char for saving the output.
  • BufferSize: size of the character array of the output buffer.
Returns:
  • ErrorCode, On success, it returns 0 or ErrorCode_OK.


NatNetClient::CopyFrame

void   CopyFrame( sFrameOfMocapData* pSrc, sFrameOfMocapData* pDst );
Description
This helper function performs a deep copy of frame data from pSrc into pDst. Some members of pDst will be dynamically allocated; call NatNetClient::FreeFrame method with pDst input to clean them up.
Input Parameters:
  • Pointer to two sFrameOfMocapData variables to copy from (pSrc) and copy to (pDst).
Returns:
  • ErrorCode, On success, it returns 0 or ErrorCode_OK.


NatNetClient::FreeFrame

void   FreeFrame( sFrameOfMocapData* pFrame );
Description
Frees the dynamic members of a frame copy created using CopyFrame. Do not call this on any frame that was not the destination of such a copy.
Input Parameters:
  • sFrameOfMocapData that has been copied using the NatNetClient::CopyFrame method.
Returns:
  • ErrorCode, On success, it returns 0 or ErrorCode_OK.