Download

Need help translating a header file for UE4 use

The original was this


typedef struct _sixenseControllerData {
  float pos[3];
  float rot_mat[3][3];
  float joystick_x;
  float joystick_y;
  float trigger;
  unsigned int buttons;
  unsigned char sequence_number;
  float rot_quat[4];
  unsigned short firmware_revision;
  unsigned short hardware_revision;
  unsigned short packet_type;
  unsigned short magnetic_frequency;
  int enabled;
  int controller_index;
  unsigned char is_docked;
  unsigned char which_hand;
  unsigned char hemi_tracking_enabled;
} sixenseControllerData;

I changed it to this


USTRUCT()
struct _sixenseControllerData
{

	GENERATED_USTRUCT_BODY()

	UPROPERTY()
	float pos[3];
	
	UPROPERTY()
	float rot_mat[3][3];
	
	UPROPERTY()
	float joystick_x;
	
	UPROPERTY()
	float joystick_y;
	
	UPROPERTY()
	float trigger;
	
	UPROPERTY()
	unsigned int buttons;
	
	UPROPERTY()
	unsigned char sequence_number;
	
	UPROPERTY()
	float rot_quat[4];
	
	UPROPERTY()
	unsigned short firmware_revision;
	
	UPROPERTY()
	unsigned short hardware_revision;
	
	UPROPERTY()
	unsigned short packet_type;
	
	UPROPERTY()
	unsigned short magnetic_frequency;
	
	UPROPERTY()
	int enabled;
	
	UPROPERTY()
	int controller_index;
	
	UPROPERTY()
	unsigned char is_docked;
	
	UPROPERTY()
	unsigned char which_hand;
	
	UPROPERTY()
	unsigned char hemi_tracking_enabled;
	
} sixenseControllerData;

However, I get “error C2144: syntax error : ‘float’ should be preceded by ‘;’” and “error C4430: missing type specifier - int assumed. Note: C++ does not support default-int” on my first variable in the struct as well as similar errors throughout. I suspect it has to do with pos being a set of three floats rather than a single float, but I may be completely wrong. Any help is much appreciated.

First you define your USTRUCT, above your class definition (or in a static library)



USTRUCT()
struct FSixenseControllerData
{

	GENERATED_USTRUCT_BODY()

	UPROPERTY()
	float pos[3];
	
	UPROPERTY()
	float rot_mat[3][3];
	
	UPROPERTY()
	float joystick_x;
	
	UPROPERTY()
	float joystick_y;
	
	UPROPERTY()
	float trigger;
	
	UPROPERTY()
	unsigned int buttons;
	
	UPROPERTY()
	unsigned char sequence_number;
	
	UPROPERTY()
	float rot_quat[4];
	
	UPROPERTY()
	unsigned short firmware_revision;
	
	UPROPERTY()
	unsigned short hardware_revision;
	
	UPROPERTY()
	unsigned short packet_type;
	
	UPROPERTY()
	unsigned short magnetic_frequency;
	
	UPROPERTY()
	int enabled;
	
	UPROPERTY()
	int controller_index;
	
	UPROPERTY()
	unsigned char is_docked;
	
	UPROPERTY()
	unsigned char which_hand;
	
	UPROPERTY()
	unsigned char hemi_tracking_enabled;
 
        //You must include constructor
       FSixenseControllerData()
       {
           //your default values
       }
	
};


Now it is an official variable type that you declare inside your class



UPROPERTY()
FSixenseControllerData MySixthSense;



F

all struct types must start with F 

USTRUCT() tutorial

Here is my USTRUCT() tutorial!

USTRUCT TUTORIAL

Thanks, I forgot all about the prefixes. I’m still getting the “‘float’ should be preceded by ‘;’” and “error C4430: missing type specifier” though. I should probably post the whole header.
Original




#ifndef _SIXENSE_H_
#define _SIXENSE_H_

#if defined(WIN32)
  #ifdef SIXENSE_STATIC_LIB
    #define SIXENSE_EXPORT 
  #else
    #ifdef SIXENSE_BUILDING_DLL
      #define SIXENSE_EXPORT __declspec(dllexport)
    #else
      #define SIXENSE_EXPORT __declspec(dllimport)
    #endif
  #endif
#else
  #define SIXENSE_EXPORT 
#endif

#define SIXENSE_BUTTON_BUMPER   (0x01<<7)
#define SIXENSE_BUTTON_JOYSTICK (0x01<<8)
#define SIXENSE_BUTTON_1        (0x01<<5)
#define SIXENSE_BUTTON_2        (0x01<<6)
#define SIXENSE_BUTTON_3        (0x01<<3)
#define SIXENSE_BUTTON_4        (0x01<<4)
#define SIXENSE_BUTTON_START    (0x01<<0)

#define SIXENSE_SUCCESS 0
#define SIXENSE_FAILURE -1

#define SIXENSE_MAX_CONTROLLERS 4

typedef struct _sixenseControllerData {
  float pos[3];
  float rot_mat[3][3];
  float joystick_x;
  float joystick_y;
  float trigger;
  unsigned int buttons;
  unsigned char sequence_number;
  float rot_quat[4];
  unsigned short firmware_revision;
  unsigned short hardware_revision;
  unsigned short packet_type;
  unsigned short magnetic_frequency;
  int enabled;
  int controller_index;
  unsigned char is_docked;
  unsigned char which_hand;
  unsigned char hemi_tracking_enabled;
} sixenseControllerData;

typedef struct _sixenseAllControllerData {
  sixenseControllerData controllers[4];
} sixenseAllControllerData;

#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
extern "C" {
#endif

SIXENSE_EXPORT int sixenseInit( void );
SIXENSE_EXPORT int sixenseExit( void );

SIXENSE_EXPORT int sixenseGetMaxBases();
SIXENSE_EXPORT int sixenseSetActiveBase( int i );
SIXENSE_EXPORT int sixenseIsBaseConnected( int i );

SIXENSE_EXPORT int sixenseGetMaxControllers( void );
SIXENSE_EXPORT int sixenseIsControllerEnabled( int which );
SIXENSE_EXPORT int sixenseGetNumActiveControllers();

SIXENSE_EXPORT int sixenseGetHistorySize();

SIXENSE_EXPORT int sixenseGetData( int which, int index_back, sixenseControllerData * );
SIXENSE_EXPORT int sixenseGetAllData( int index_back, sixenseAllControllerData * );
SIXENSE_EXPORT int sixenseGetNewestData( int which, sixenseControllerData * );
SIXENSE_EXPORT int sixenseGetAllNewestData( sixenseAllControllerData * );

SIXENSE_EXPORT int sixenseSetHemisphereTrackingMode( int which_controller, int state );
SIXENSE_EXPORT int sixenseGetHemisphereTrackingMode( int which_controller, int *state );

SIXENSE_EXPORT int sixenseAutoEnableHemisphereTracking( int which_controller );

SIXENSE_EXPORT int sixenseSetHighPriorityBindingEnabled( int on_or_off );
SIXENSE_EXPORT int sixenseGetHighPriorityBindingEnabled( int *on_or_off );

SIXENSE_EXPORT int sixenseTriggerVibration( int controller_id, int duration_100ms, int pattern_id );

SIXENSE_EXPORT int sixenseSetFilterEnabled( int on_or_off );
SIXENSE_EXPORT int sixenseGetFilterEnabled( int *on_or_off );

SIXENSE_EXPORT int sixenseSetFilterParams( float near_range, float near_val, float far_range, float far_val );
SIXENSE_EXPORT int sixenseGetFilterParams( float *near_range, float *near_val, float *far_range, float *far_val );

SIXENSE_EXPORT int sixenseSetBaseColor( unsigned char red, unsigned char green, unsigned char blue );
SIXENSE_EXPORT int sixenseGetBaseColor( unsigned char *red, unsigned char *green, unsigned char *blue );

#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
}
#endif

#endif /* _SIXENSE_H_ */


Mine



#pragma once

#include "GameFramework/Actor.h"

#define _SIXENSE_H_

#define SIXENSE_EXPORT __declspec(dllimport)

#define SIXENSE_BUTTON_BUMPER   (0x01<<7)
#define SIXENSE_BUTTON_JOYSTICK (0x01<<8)
#define SIXENSE_BUTTON_1        (0x01<<5)
#define SIXENSE_BUTTON_2        (0x01<<6)
#define SIXENSE_BUTTON_3        (0x01<<3)
#define SIXENSE_BUTTON_4        (0x01<<4)
#define SIXENSE_BUTTON_START    (0x01<<0)

#define SIXENSE_SUCCESS 0
#define SIXENSE_FAILURE -1

#define SIXENSE_MAX_CONTROLLERS 4

USTRUCT()
struct FSixenseControllerData
{
	GENERATED_USTRUCT_BODY()

	float pos[3];
	
	float rot_mat[3][3];
	
	float joystick_x;
	
	float joystick_y;
	
	float trigger;
	
	unsigned int buttons;
	
	unsigned char sequence_number;
	
	float rot_quat[4];
	
	unsigned short firmware_revision;
	
	unsigned short hardware_revision;
	
	unsigned short packet_type;
	
	unsigned short magnetic_frequency;
	
	int enabled;
	
	int controller_index;
	
	unsigned char is_docked;
	
	unsigned char which_hand;
	
	unsigned char hemi_tracking_enabled;
 
    //You must include constructor
    FSixenseControllerData()
    {
		//your default values
    }
};

USTRUCT()
struct FSixenseAllControllerData
{
	GENERATED_USTRUCT_BODY()

	FSixenseControllerData controllers[4];
	
	//You must include constructor
    FSixenseAllControllerData()
    {
		//your default values
    }
		
};

UCLASS()
class ASixense : public AActor
{
	GENERATED_UCLASS_BODY();

	UPROPERTY()
	FSixenseControllerData MyControllerData;
	
	UPROPERTY()
	FSixenseAllControllerData MyAllControllerData;
	
	virtual void BeginPlay() OVERRIDE;

	SIXENSE_EXPORT int sixenseInit(void);
	SIXENSE_EXPORT int sixenseExit(void);

	SIXENSE_EXPORT int sixenseGetMaxBases();
	SIXENSE_EXPORT int sixenseSetActiveBase(int i);
	SIXENSE_EXPORT int sixenseIsBaseConnected(int i);

	SIXENSE_EXPORT int sixenseGetMaxControllers(void);
	SIXENSE_EXPORT int sixenseIsControllerEnabled(int which);
	SIXENSE_EXPORT int sixenseGetNumActiveControllers();

	SIXENSE_EXPORT int sixenseGetHistorySize();

	SIXENSE_EXPORT int sixenseGetData(int which, int index_back, FSixenseControllerData *);
	SIXENSE_EXPORT int sixenseGetAllData(int index_back, FSixenseAllControllerData *);
	SIXENSE_EXPORT int sixenseGetNewestData(int which, FSixenseControllerData *);
	SIXENSE_EXPORT int sixenseGetAllNewestData(FSixenseAllControllerData *);

	SIXENSE_EXPORT int sixenseSetHemisphereTrackingMode(int which_controller, int state);
	SIXENSE_EXPORT int sixenseGetHemisphereTrackingMode(int which_controller, int *state);

	SIXENSE_EXPORT int sixenseAutoEnableHemisphereTracking(int which_controller);

	SIXENSE_EXPORT int sixenseSetHighPriorityBindingEnabled(int on_or_off);
	SIXENSE_EXPORT int sixenseGetHighPriorityBindingEnabled(int *on_or_off);

	SIXENSE_EXPORT int sixenseTriggerVibration(int controller_id, int duration_100ms, int pattern_id);

	SIXENSE_EXPORT int sixenseSetFilterEnabled(int on_or_off);
	SIXENSE_EXPORT int sixenseGetFilterEnabled(int *on_or_off);

	SIXENSE_EXPORT int sixenseSetFilterParams(float near_range, float near_val, float far_range, float far_val);
	SIXENSE_EXPORT int sixenseGetFilterParams(float *near_range, float *near_val, float *far_range, float *far_val);

	SIXENSE_EXPORT int sixenseSetBaseColor(unsigned char red, unsigned char green, unsigned char blue);
	SIXENSE_EXPORT int sixenseGetBaseColor(unsigned char *red, unsigned char *green, unsigned char *blue);

};


It would seem that “GENERATED_…” lines are all red squiggly in visual studio. Removing them stops the requests for “;” but causes new errors, unsurprisingly…

BlackRang666,

Can you post the entire new header file?

Also, not all basic C++ types are supported as UProperties. Use int8, int16, int32, uint8, uint16, uint32 etc. Search for “USTRUCT” in the code base for plenty of examples.

Turns out it was because there was no .generated.h file. I was doing this entirely wrong anyway though. Looks like I should be dumping the sixense sdk into the ThirdParty folder…