Writing vector data into a file!
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
Hi Friends!, I'm a very beginner in c++, I have been working on a code to develop a tracking game using haptic device as a controller. I'm using a library called Chai3D and OpenGL for graphics. I want to make provision in my code to write certain objects in a vector to a .txt file. I'm including a section of my code where I've to save some objects into a file:
void updateHaptics(void)
{
// main haptic simulation loop
while(simulationRunning)
{
// for each device// read position of haptic devices 1,2 cVector3d newPosition1,newPosition2; //hapticDevices\[i\]->getPosition(newPosition); hapticDevices\[0\]->getPosition(newPosition1); hapticDevices\[1\]->getPosition(newPosition2); // read orientation of haptic devices 1, 2 cMatrix3d newRotation1, newRotation2; hapticDevices\[0\]->getRotation(newRotation1); hapticDevices\[1\]->getRotation(newRotation2); // update position and orientation of cursors cursors\[0\]->setPos(newPosition1); cursors\[1\]->setPos(newPosition2); cursors\[0\]->setRot(newRotation1); cursors\[1\]->setRot(newRotation2); // read linear velocity from devices 1,2 cVector3d linearVelocity1, linearVelocity2; hapticDevices\[0\]->getLinearVelocity(linearVelocity1); hapticDevices\[1\]->getLinearVelocity(linearVelocity2); // update arrow for device 1 velocityVectors\[0\]->m\_pointA = newPosition1; velocityVectors\[0\]->m\_pointB = cAdd(newPosition1, linearVelocity1); // update arrow for device 2 velocityVectors\[1\]->m\_pointA = newPosition2; velocityVectors\[1\]->m\_pointB = cAdd(newPosition2, linearVelocity2); // Apply a coupled force F1= Kp (X1-X2) double Kp = 60.0; // \[N/m\] double Kb = 3.0; // \[N.s/m\] cVector3d newForce (0,0,0); cVector3d coupledForce1 = cMul(Kp, (newPosition1-newPosition2))-(cMul(Kb, (linearVelocity2))); newForce.add(coupledForce1); hapticDevices\[1\]->setForce(newForce);// send computed force to haptic device 1 cVector3d newForce1 (0,0,0); cVector3d coupledForce2 = cMul(Kp, (newPosition2-newPosition1))-(cMul(Kb, (linearVelocity1))); newForce1.add(coupledForce2); hapticDevices\[0\]->setForce(newForce1);// send computed force to haptic device 0 } // exit haptics thread simulationFinished = true;