1 /*---------------------------------------------------------------------------* 2 Project: KPAD library 3 File: KPADinside.h 4 Programmers: Keizo Ohta 5 HIRATSU Daisuke 6 7 Copyright 2005 Nintendo. All rights reserved. 8 9 These coded instructions, statements, and computer programs contain 10 proprietary information of Nintendo of America Inc. and/or Nintendo 11 Company Ltd., and are protected by Federal copyright law. They may 12 not be disclosed to third parties or copied or duplicated in any form, 13 in whole or in part, without the prior written consent of Nintendo. 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef KPAD_INSIDE_H__ 17 #define KPAD_INSIDE_H__ 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #include <revolution/wpad.h> 24 25 26 /******************************************************************************* 27 DEFINE 28 *******************************************************************************/ 29 //----- Constant used to calculate various things 30 #define KPAD_CMOS_FOV WPAD_DPD_ANGLE // Field of view of CMOS lens 31 #define KPAD_CMOS_HFOV_TAN 0.383864f // Tangent to half of angle of CMOS_FOV 32 33 #define KPAD_CMOS_RESO_WX 128 // CMOS resolution 34 #define KPAD_CMOS_RESO_WY 96 35 #define KPAD_CMOS_RESO_CX (KPAD_CMOS_RESO_WX / 2) 36 #define KPAD_CMOS_RESO_CY (KPAD_CMOS_RESO_WY / 2) 37 38 #define KPAD_DPD_RESO_WX WPAD_DPD_IMG_RESO_WX // DPD resolution 39 #define KPAD_DPD_RESO_WY WPAD_DPD_IMG_RESO_WY 40 #define KPAD_DPD_RESO_CX (KPAD_DPD_RESO_WX / 2) 41 #define KPAD_DPD_RESO_CY (KPAD_DPD_RESO_WY / 2) 42 43 #define KPAD_USE_OBJECTS 2 // Number of marks to be used for grasping the position 44 45 #define KPAD_BTN_RPT_TIME_MAX 20000 // btn_repeat_time range (cannot assume this value) 46 #define KPAD_BTN_NO_RPT_DELAY 40000 // Delay setting when repeat not set 47 48 49 /******************************************************************************* 50 TYPEDEF 51 *******************************************************************************/ 52 typedef struct { 53 Vec2 center ; // Center of gravity coordinates (coordinate system where the horizontal range of CMOS is +/-1 54 55 s8 error_fg ; // -1: Not displayed, 0: OK, 1: Too far outside, 2: Same coordinates 56 s8 state_fg ; // -1: Predicted value, 0: Normal 57 s8 _fg_1 ; // Preparations 58 s8 _fg_2 ; // Preparations 59 } KPADObject ; 60 61 62 typedef struct { 63 KPADStatus status ; 64 65 //----- Variable for adjusting controller response 66 f32 pos_play_radius ; // Play radius (size in the pos coordinate system) 67 f32 pos_sensitivity ; // Sensitivity (0: Insensitive -> 1: Sensitive) 68 69 f32 hori_play_radius ; // Adjust horizon sensitivity 70 f32 hori_sensitivity ; // 71 72 f32 dist_play_radius ; // Adjust dist sensitivity 73 f32 dist_sensitivity ; // 74 75 f32 acc_play_radius ; // Adjust acc sensitivity 76 f32 acc_sensitivity ; // 77 78 //----- DPD calibration values 79 f32 dist_org ; // Distance after calibration 80 Vec2 accXY_nrm_hori ; // XY acceleration direction when the controller is in the horizontal plane 81 Vec2 sec_nrm_hori ; // Direction from left mark to right mark when the controller is in the horizontal plane 82 Vec2 center_org ; // Coordinates during calibration 83 f32 dpd2pos_scale ; // Scale value where the left/right end of pointing is within +/- of the ??sassho?? 84 85 //----- Variables used for internal control 86 KPADObject kobj_sample[ WPAD_DPD_MAX_OBJECTS ] ; // All retrieved marks are included 87 KPADObject kobj_regular[ KPAD_USE_OBJECTS ] ; // Left-to-right order (bottom-to-top order when oriented vertically) 88 89 s16 valid_objs ; // Number of valid objects 90 u16 work_ct ; // Number of times DPD processing is performed per game frame 91 92 s16 wpad_chan_no ; // IO channel number 93 s16 wpad_ring_idx ; // Processed ring buffer 94 WPADCLStatus wpad_ring_bf[ KPAD_RING_BUFS ] ;// Buffer used to store SDK variable 95 96 f32 sec_length ; // Distance from left mark to right mark 97 Vec2 sec_nrm ; // Direction from left mark to right mark 98 f32 sec_dist ; // Raw distance from TV (in meters) 99 f32 trust_sec_length ; // Reliable distance between sections is saved here 100 101 Vec hard_acc ; // Raw acceleration 102 103 Vec2 obj_horizon ; // Orientation calculated based on the object 104 Vec2 acc_horizon ; // Orientation calculated based on the acceleration (left-right) 105 106 Vec2 ah_circle_pos ; // Point following the acc_horizon 107 u16 ah_circle_ct ; // Countdown if within a certain range (stop at zero) 108 109 u8 dpd_valid2_ct ; // Number of consecutive successful recognitions of two points 110 s8 _fg_4 ; // Preparations 111 112 //----- Control button 113 u16 btn_repeat_time ; // Ongoing time count 114 u16 btn_repeat_next ; // Next time to set flag 115 u16 btn_repeat_delay ; // Time to start repeat 116 u16 btn_repeat_pulse ; // Time between repeats 117 //----- for a Classic Controller unit 118 u16 btn_cl_repeat_time ; // Ongoing time count 119 u16 btn_cl_repeat_next ; // Next time to set flag 120 u16 btn_cl_repeat_delay ; // Time to start repeat 121 u16 btn_cl_repeat_pulse ; // Time between repeats 122 123 } KPADInsideStatus ; 124 125 126 /******************************************************************************* 127 EXTERNAL WORK 128 *******************************************************************************/ 129 //----- Various adjustments 130 extern f32 kp_obj_interval ; // Distance between both marks (in meters) 131 extern f32 kp_acc_horizon_pw ; // Conditions when calculating the rotation from the acceleration 132 extern f32 kp_ah_circle_radius ; // Radius used to determine if the controller is at rest 133 extern f32 kp_ah_circle_pw ; // Sensitivity conditions used to determine if the controller is at rest 134 extern u16 kp_ah_circle_ct ; // Count for determining if the controller is at rest 135 136 //----- Numeric values viewed as errors 137 extern f32 kp_err_outside_frame ; // Peripheral width where center of gravity coordinates are disabled (peripheral light may not be entirely displayed) 138 extern f32 kp_err_dist_min ; // Maximum operation distance (in meters) 139 extern f32 kp_err_dist_max ; // Maximum operation distance (in meters) 140 extern f32 kp_err_dist_speed ; // Allowable range of variation in distance (in meters) 141 extern f32 kp_err_first_inpr ; // Inner product of acceleration slope and object inclination when selecting first two points 142 extern f32 kp_err_next_inpr ; // Allowable range in variation of inclination (inner product) 143 extern f32 kp_err_acc_inpr ; // Allowable range of inner product with acceleration slope when controller has been brought to rest 144 extern f32 kp_err_up_inpr ; // Allowable range of inner product when controller is facing up 145 extern f32 kp_err_near_pos ; // Distance from last point when selecting the next point 146 147 //----- �j�o�`�c unit 148 extern KPADInsideStatus inside_kpads[] ; 149 150 151 /******************************************************************************* 152 EXTERNAL FUNCTION 153 *******************************************************************************/ 154 155 156 #ifdef __cplusplus 157 } 158 #endif 159 160 #endif // KPAD_INSIDE_H__ 161