Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Writing vector data into a file!

Writing vector data into a file!

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devc++announcementlearning
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 9350237
    wrote on last edited by
    #1

    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;
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups