Operations on the TXT file

Source: Internet
Author: User

// Leaf. cpp: Defines the entry point for the console application.

//

# Include "stdAfx. h"

# Define graphfile "t3.WRL" // enter the name of the imported TXT file.

# Define texturefile "bigLeaf1.JPG" // The Name Of The read texture image

Int numOfCoord; // Number of vertex coordinates stored

Int numOfTexCoord; // Number of texture coordinates stored

Int numOfIndex; // Number of indexes stored

Float (* tempCoord) [3];

Int * tempIndex;

Float (* tempTexCoord) [2];

// Read the scenario data in the TXT file

Void readFile (const char * filename)

{

// Create an external file for reading

SoInput myGraphInput;

If (! MyGraphInput. openFile (filename ))

{

Fprintf (stderr, "Cannot open file % s", filename );

Exit (1 );

}

SoVRMLGroup * myGraph = SoDB: readallml (& myGraphInput );

If (myGraph = NULL)

{

Fprintf (stderr, "Problem reading file ");

Exit (1 );

}

MyGraphInput. closeFile ();

// Read the TXT file

// Search and retrieve the SoVRMLShape Node

MyGraph-> ref ();

SoVRMLShape * Shape = new SoVRMLShape;

SoSearchAction search;

Search. setType (SoVRMLShape: getClassTypeId ());

Search. setInterest (SoSearchAction: FIRST );

Search. apply (myGraph );

If (search. getPath () = 0)

{

Printf ("error! ");

Exit (1 );

}

Else

{

Printf ("right ");

Shape = (SoVRMLShape *) search. getPath ()-> getTail ();

Shape-> setOverride (TRUE );

}

// Obtain the geometry information, which is the container pointing to the pointer of the SoVRMLIndexedFaceSet Node

SoVRMLIndexedFaceSet * indexedFaceSet = new SoVRMLIndexedFaceSet;

IndexedFaceSet = (SoVRMLIndexedFaceSet *) Shape-> geometry. getValue ();

// Obtain the coordinate information of the vertex and save it to the global variable array.

SoVRMLCoordinate * coordInate = new SoVRMLCoordinate;

CoordInate = (SoVRMLCoordinate *) indexedFaceSet-> coord. getValue ();

NumOfCoord = coordInate-> point. getNum ();

TempCoord = new float [numOfCoord] [3];

For (int I = 0; I <numOfCoord; I ++)

{

For (int j = 0; j <3; j ++)

{

TempCoord [I] [j] = coordInate-> point [I] [j];

// Printf ("% f ",);

}

}

// Obtain the coordinate index information of the vertex and save it to the global variable array.

NumOfIndex = indexedFaceSet-> coordIndex. getNum ();

TempIndex = new int [numOfIndex];

For (int k = 0; k <numOfIndex; k ++)

{

TempIndex [k] = indexedFaceSet-> coordIndex [k];

}

// Obtain the coordinate information of the texture and save it to the global variable array.

SoTextureCoordinate2 * textureCoord = new SoTextureCoordinate2;

TextureCoord = (SoTextureCoordinate2 *) indexedFaceSet-> texCoord. getValue ();

NumOfTexCoord = textureCoord-> point. getNum ();

TempTexCoord = new float [numOfTexCoord] [2];

For (int n = 0; n <numOfTexCoord; n ++)

{

For (int p = 0; p <2; p ++)

{

TempTexCoord [n] [p] = textureCoord-> point [n] [p];

}

}

}

// Scenario data Initialization

Void drawFace (SoIndexedFaceSet * myIndexedFaceSet)

{

SoMFVec3f coordVec3f;

SoMFInt32 coordIndex;

SoMFVec2f textureCoordVec2f;

For (int j = 0; j <numOfCoord; j ++)

{

CoordVec3f. set1Value (j, tempCoord [j]);

}

For (int k = 0; k <numOfIndex; k ++)

{

CoordIndex. set1Value (k, tempIndex [k]);

}

For (int I = 0; I <numOfTexCoord; I ++)

{

TextureCoordVec2f. set1Value (I, tempTexCoord [I]);

}

SoVertexProperty * myVertexProperty = new SoVertexProperty;

// Set the coordinates of the vertex

MyVertexProperty-> vertex = coordVec3f;

// Set the loss of the Plane Method

MyVertexProperty-> normal. set1Value (0, SbVec3f (0, 1, 0 ));

// Set texture coordinates

MyVertexProperty-> texCoord = textureCoordVec2f;

// Defines the method of Unbinding

MyVertexProperty-> normalBinding = SoNormalBinding: OVERALL;

// Define a surface set

MyIndexedFaceSet-> coordIndex = coordIndex;

MyIndexedFaceSet-> vertexProperty. setValue (myVertexProperty );

}

// Timer sensor callback function

Static void timertra (void * data, SoSensor *)

{

Static SbBool direction = FALSE;

SoIndexedFaceSet * myIndexedFaceSet = (SoIndexedFaceSet *) data;

SoMFVec3f coordVec3f;

SoMFInt32 coordIndex;

SoMFVec2f textureCoordVec2f;

// Modify vertex coordinates to realize Fluctuation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.