summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authordapetcu21 <dapetcu21@gmail.com>2010-08-29 17:51:55 +0000
committerdapetcu21 <dapetcu21@gmail.com>2010-08-29 17:51:55 +0000
commitad6ddfa18c7c6596e702b4756957ffbc3f5ac1d7 (patch)
tree811d4c96449f72b6bb83afc3fde3df252becef50 /Source
parenta3df65bd027f504a7c948a5076280f9b22555ef4 (diff)
IR pointer rotation finally working... Added a low-pass filter over sin and cos, but I still get some jittering... I suspect it's the numeric values... Billiard? Can you please help me on this?
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6146 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source')
-rw-r--r--Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp35
-rw-r--r--Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h2
2 files changed, 27 insertions, 10 deletions
diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp
index 4fd416757a..e876445257 100644
--- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp
+++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.cpp
@@ -234,6 +234,8 @@ void Wiimote::Reset()
Wiimote::Wiimote( const unsigned int index )
: m_index(index)
+ , ir_sin(0)
+ , ir_cos(1)
// , m_sound_stream( NULL )
{
// ---- set up all the controls ----
@@ -417,6 +419,13 @@ void Wiimote::GetAccelData(u8* const data, u8* const buttons)
buttons[1]|=((u8(cy*2)&1)<<5)|((u8(cz*2)&1)<<6);
}
}
+#define kCutoffFreq 5.0f
+inline void LowPassFilter(double & var, double newval, double period)
+{
+ double RC=1.0/kCutoffFreq;
+ double alpha=period/(period+RC);
+ var = newval * alpha + var * (1.0 - alpha);
+}
void Wiimote::GetIRData(u8* const data, bool use_accel)
{
@@ -428,7 +437,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
if (has_focus)
{
float xx = 10000, yy = 0, zz = 0;
- double sin,cos;
+ double nsin,ncos;
if (use_accel)
{
@@ -440,22 +449,25 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
{
ax/=len;
az/=len; //normalizing the vector
- sin=-ax;
- cos=az;
+ nsin=ax;
+ ncos=az;
} else
{
- sin=0;
- cos=1;
+ nsin=0;
+ ncos=1;
}
// PanicAlert("%d %d %d\nx:%f\nz:%f\nsin:%f\ncos:%f",accel->x,accel->y,accel->z,ax,az,sin,cos);
//PanicAlert("%d %d %d\n%d %d %d\n%d %d %d",accel->x,accel->y,accel->z,calib->zero_g.x,calib->zero_g.y,calib->zero_g.z,
// calib->one_g.x,calib->one_g.y,calib->one_g.z);
} else
{
- sin=0; //m_tilt stuff here (can't figure it out yet....)
- cos=1;
+ nsin=0; //m_tilt stuff here (can't figure it out yet....)
+ ncos=1;
}
+ LowPassFilter(ir_sin,nsin,1.0f/60);
+ LowPassFilter(ir_cos,ncos,1.0f/60);
+
m_ir->GetState(&xx, &yy, &zz, true);
UDPTLayer::GetIR(m_udp, &xx, &yy, &zz);
@@ -467,7 +479,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
static const double bnddown=0.85;
static const double bndleft=0.443364;
static const double bndright=-0.443364;
- static const double dist1=250.0f/camWidth; //this seems the optimal distance for zelda
+ static const double dist1=100.f/camWidth; //this seems the optimal distance for zelda
static const double dist2=1.2f*dist1;
for (int i=0; i<4; i++)
@@ -487,9 +499,12 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
static Matrix scale;
static bool isscale=false;
if (!isscale)
+ {
MatrixScale(scale,1,camWidth/camHeight,1);
- //MatrixRotationByZ(rot,sin,cos);
- MatrixIdentity(rot);
+ //MatrixIdentity(scale);
+ }
+ MatrixRotationByZ(rot,ir_sin,ir_cos);
+ //MatrixIdentity(rot);
MatrixMultiply(tot,scale,rot);
for (int i=0; i<4; i++)
diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h
index 5cc96d7944..1be37eda18 100644
--- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h
+++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteEmu.h
@@ -141,6 +141,8 @@ private:
// WiiMote accel data
AccelData m_accel;
+ double ir_sin,ir_cos; //for the low pass filter
+
//UDPWiimote
UDPWrapper* m_udp;