Click here to Skip to main content
16,011,869 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: To copy path of selected file or folder Pin
jeron118-Mar-15 8:11
jeron118-Mar-15 8:11 
AnswerREPOST Pin
Richard Deeming18-Mar-15 8:37
mveRichard Deeming18-Mar-15 8:37 
QuestionHow to fast read excel file, with VC2005 Pin
lichengbyd18-Mar-15 2:46
lichengbyd18-Mar-15 2:46 
AnswerRe: How to fast read excel file, with VC2005 Pin
Jochen Arndt18-Mar-15 3:09
professionalJochen Arndt18-Mar-15 3:09 
GeneralRe: How to fast read excel file, with VC2005 Pin
lichengbyd18-Mar-15 3:50
lichengbyd18-Mar-15 3:50 
GeneralRe: How to fast read excel file, with VC2005 Pin
Jochen Arndt18-Mar-15 4:02
professionalJochen Arndt18-Mar-15 4:02 
GeneralRe: How to fast read excel file, with VC2005 Pin
lichengbyd18-Mar-15 4:30
lichengbyd18-Mar-15 4:30 
QuestionWriting Vector object into a .txt file Pin
Member 935023718-Mar-15 0:16
Member 935023718-Mar-15 0:16 
Hi all!,

I've been working on a code to develop a tracking game with a haptic device as controller. I use library Chai3D and OpenGL.

I need to save some information of the game during the program execution. And write into a txt file.

I'm attaching part of my code where mentioning vector objects need to be saved:

C++
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;
}




On the above code I need to save these objects into a file

cVector3d newForce
cVector3d NewForce1


Please help me how to make a provision to save these file effectively into a txt file.

Basically I dont have much idea on saving , writing into files.


Thanks in advance!
AnswerRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 0:46
professionalJochen Arndt18-Mar-15 0:46 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023718-Mar-15 1:38
Member 935023718-Mar-15 1:38 
AnswerRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 1:59
professionalJochen Arndt18-Mar-15 1:59 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023718-Mar-15 5:03
Member 935023718-Mar-15 5:03 
AnswerRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 5:19
professionalJochen Arndt18-Mar-15 5:19 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023718-Mar-15 6:33
Member 935023718-Mar-15 6:33 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 6:59
professionalJochen Arndt18-Mar-15 6:59 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023718-Mar-15 22:32
Member 935023718-Mar-15 22:32 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt18-Mar-15 22:44
professionalJochen Arndt18-Mar-15 22:44 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023719-Mar-15 22:27
Member 935023719-Mar-15 22:27 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt19-Mar-15 22:29
professionalJochen Arndt19-Mar-15 22:29 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023723-Mar-15 5:12
Member 935023723-Mar-15 5:12 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt23-Mar-15 5:57
professionalJochen Arndt23-Mar-15 5:57 
GeneralRe: Writing Vector object into a .txt file Pin
Member 935023723-Mar-15 6:20
Member 935023723-Mar-15 6:20 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt23-Mar-15 6:44
professionalJochen Arndt23-Mar-15 6:44 
GeneralRe: Writing Vector object into a .txt file Pin
Richard Andrew x6423-Mar-15 8:39
professionalRichard Andrew x6423-Mar-15 8:39 
GeneralRe: Writing Vector object into a .txt file Pin
Jochen Arndt23-Mar-15 21:53
professionalJochen Arndt23-Mar-15 21:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.