Thought I might as well show my horrible coding skills

Basically I wanted to try and implement proper force feedback to try and simulate riding a real bike, but figured coding that would be far too complex considering I have never programmed in C++ before

and of course I'd have to build a compatible controller first. So I decided to try a simple rumble at first, to try and find my feet. So a few video tutorials later, some reading up and some nice advice from JLV, I came up with a VERY rough rumble, which when the source code is analysed will probably be deemed unsuitable for human consumption so to speak.

Anyway, basically it takes three samples from the streaming output, compares the x,y,z positions of the camera at each snapshot of time and approximates an acceleration. I really didn't like my method of approximating acceleration but couldn't think of another simple way....it's open to suggestions

Then finds the magnitude of the overall acceleration, and sort of roughly translates this to a rumble value for the motors on the controller. One of the motors is the tingly vibration and the other is the cluncky vibration. I wanted to make it so that forward acceleration was tingly, and any other acceleration and deceleration was clunky, but I'd need to use the angles etc for that and I wanted to make sure I was on the right lines first so for now it feels kind of random.
Anyway this is the code
Code: Select all
#include "CXBOXController.h"
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
CXBOXController* Player1;
int main()
{
char one[500];
char two[500];
char three[500];
int i = 0;
double x1 ;
double x2 ;
double x3 ;
double y1 ;
double y2 ;
double y3 ;
double z1 ;
double z2 ;
double z3 ;
double t1;
double t2;
double t3;
double a;
double ax;
double ay;
double az;
double number;
int v1 = 0;
int v2 = 0;
Player1 = new CXBOXController(1);
do
{
fgets(one, 500, stdin);
sscanf (one,"%*c %*c %*c %LG %*c %*c %*c %LG %*c %*c %*c %LG %*c %*c %*c %LG ", &t1, &x1, &y1, &z1);
fgets(two, 500, stdin);
sscanf (two,"%*c %*c %*c %LG %*c %*c %*c %LG %*c %*c %*c %LG %*c %*c %*c %LG ", &t2, &x2, &y2, &z2);
fgets(three, 500, stdin);
sscanf (three,"%*c %*c %*c %LG %*c %*c %*c %LG %*c %*c %*c %LG %*c %*c %*c %LG ", &t3, &x3, &y3, &z3);
ax = (((x2-x3)/(t3-t2))-((x1-x2)/(t2-t1)))/(t3-t1)*10;
ay = (((y2-y3)/(t3-t2))-((y1-y2)/(t2-t1)))/(t3-t1)*10;
az = (((z2-z3)/(t3-t2))-((z1-z2)/(t2-t1)))/(t3-t1)*10;
number=pow(ax,2)+pow(ay,2)+pow(az,2);
a= sqrt(number);
if(ax<0)
{ v1=a*20;
}
else
{ v2=a*20;
}
Player1->Vibrate(v1,v2);
;
}
while (i==0) ;
cin.get();
return( 0 );
}
The controller class was shamelessly copied from this tutorial:
http://www.codeproject.com/KB/directx/x ... input.aspx
Feedback is what I'm after really (excuse the pun

) as I know this is probably terrible coding, and is it worth continuing? I'm not going to post the executable until somebody has verified that it won't crash somebody's system.
