Skip to main content
gamedev.net
🔒 Locked

D3D float loader

Started by Verminaard Jul 2, 2000 at 1:41 AM 7 replies 700+ views
Original Post
Verminaard
Verminaard
I''m trying to write a function that loads in floats from a file to store as the x, y, z, tu, and tv parts of my FVF_VERTEX Vertex which is FVF_TEXTURE1 and FVF_XYZ. (not sure of the exact format, can''t remeber). I''m trying to do this without using a binary file, using a .map file which can be opened in notepad which will look like: 1.0000000 1.0000000 0.0000000 0.0000000 0.0000000 ... / / / / / Vertex.v.x Vertex.v.y Vertex.v.z Vertex.tu Vertex.tv so i can change the vertexes of my objects without compiling the code all the time, and can load different maps in. The problem is, i''m not sure how to load the floats in. I''ve been using fprintf to print floats into the map files which looks like: 1.0000000 , but when i try to fscanf the floats in my program crashes. Anyone know what functions i should be using to get this to work correctly. Or anyone know how i can store my file to be compatable with some input funcion you know of? Thanks.
-------------I am a Juggalo.
3dModelMan
3dModelMan
Drop the ascii format, unless you really need it for hand editing.

Here''s some sample code for loading structs straight into memory using fread, the opposite of which is fwrite (surprisingly!).


unsigned int modelverts;
stream = fopen("build01.mod", "rb");
fread(&modelverts, 2, 1, stream);
fread(&model, sizeof(D3DVERTEX), modelverts, stream);
fclose(stream);


Cheers

Matt



Check out my project at:www.btinternet.com/~Matthew.Bennett
djsteffey
djsteffey
    
#include <fstream.h>
.
.
.
.
.
.
.
ifstream in("mapFile.txt");
float x;
float y;
float z;
float tu;
float tv;
VERTEX myVertex[MAX_VERTICES];
int count = 0;

while(in >> x)
{
in >> y;
in >> z;
in >> tu;
in >> tv;
myVertex[count].x = x;
myVertex[count].y = y;
myVertex[count].z = z;
myVertex[count].tu = tu;
myVertex[count].tv = tv;
count++;
}

you also have to make sure you dont read in more vertices then you allocated space for.......like dont let count exceed MAX_VERTICES


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Julio
Julio
or if you''re using C (doesn''t matter) you could read the file to a string and then analyze the string like so:
    
char string[255];
float variable;
FILE *file;
...//load file stuff

fgets(string,255,file);
sscanf(string,"%f",&variable);
...//close file


that should work also.

JoeMont001@aol.com
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
ryoder
ryoder
use fscanf
// pseudo code will scan rows
FILE *fp = fopen("filename.map")
Vertex *v;
for i = 0 to numRows
v = verticesArray;
fscanf(fp, "%f", &v->x);
fscanf(fp, "%f", &v->y);
fscanf(fp, "%f", &v->z);
fscanf(fp, "%f", &v->u);
fscanf(fp, "%f", &v->v);
next i


MCSE, MCSD, Sun Certified Java Programmer
Pimp Daddy ;)
MCSE, MCSD, Sun Certified Java ProgrammerPimp Daddy ;)
Verminaard
Verminaard
Thanks people. I''ll try these ways and get back to you.

-------------
I am a Juggalo.
-------------I am a Juggalo.
MK42
MK42
When fscanf crashes it is often the little ''&'' to the float variable that is missing ! Too bad you didn''t post the line of code.

Ciao,

MK42
Verminaard
Verminaard
Ahhh..yes, finally I see it! I didn''t even notice the & in the code above. No wonder. Thanks people.
-------------I am a Juggalo.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.