Skip to main content
gamedev.net
🔒 Locked

[solved] Same data, different result?

Started by markookram 3 replies 750+ views
Original Post
markookram
markookram
edit Problem solved! It's one of those "it should work, but it doesn't" cases. I'm totally stumped. Basically I fill an array of CustomVertex.PositionColored[] vertices = new CustomVertex.PositionColored[1000000]; in two different ways from two different binary files. The reason for this is that one method is slow and one is fast, but needs the slow one to rewrite the data first. Now I'm trying to switch back to the slow one only to find out that it doesn't work altho the fast method basically get's it's data from the slow one! You run the slow method, it creates a new binary file and sorts the data so it can be read faster. Then the slow method reads that new binary file and get's the data faster. So I only need to run the slow method once and then I can use the fast one for debugging purposes. The final version must have the slow method that reads the original file. Right after I fill one of the vertices[offset].Position "dot" X, Y and Z I output the data from this variable. I do this for both the slow and the fast method and the data is the same. The offset of data within the vertices[offset] is the same. They are alligned. But when passing the vertices to the draw method, it draws them differently. Here is the picture of how it draws. The fast method is correct, the slow is wrong. But both use the same data and the same draw method! Anyone had a similar experience? [Edited by - markookram on January 18, 2008 1:11:21 PM]
Evil Steve
Evil Steve
Quote:
Original post by markookram
But both use the same data and the same draw method!
They clearly don't [smile] There must be some difference between them. Can we see some code? I don't really follow what you're doing...
markookram
markookram
//slow read method            FileStream fs = new FileStream("original_file.smx", FileMode.Open);            BinaryReader br = new BinaryReader(fs);            FileStream fs2 = new FileStream("rewritten_file_for_faster_reading.bin", FileMode.CreateNew);            BinaryWriter bw = new BinaryWriter(fs2);//we have filled the pointX[], pointY[], pointZ[], triangleA, triangleB, triangleC, vertexColor variables from the original_file.smx                    // #1* : writting the new binary file for faster reading                    bw.Write(pointX[triangleA]);                    bw.Write(pointY[triangleA]);                    bw.Write(pointZ[triangleA]);                    bw.Write(vertexColor[triangleA].ToArgb());                    bw.Write(pointX[triangleB]);                    bw.Write(pointY[triangleB]);                    bw.Write(pointZ[triangleB]);                    bw.Write(vertexColor[triangleB].ToArgb());                    bw.Write(pointX[triangleC]);                    bw.Write(pointY[triangleC]);                    bw.Write(pointZ[triangleC]);                    bw.Write(vertexColor[triangleC].ToArgb());                                        // #2* : filling data so it can be drawn straight away                    vertices[vert_offset].Position = new Vector3(pointX[triangleA], pointY[triangleA], pointZ[triangleA]);                    vertices[vert_offset].Color = vertexColor[j].ToArgb();                    vertices[vert_offset+1].Position = new Vector3(pointX[triangleB], pointY[triangleB], pointZ[triangleB]);                    vertices[vert_offset+1].Color = vertexColor[j+1].ToArgb();                    vertices[vert_offset+2].Position = new Vector3(pointX[triangleC], pointY[triangleC], pointZ[triangleC]);                    vertices[vert_offset+2].Color = vertexColor[j+2].ToArgb();                    //I output the vertices dot X, Y and Z to see if they match with the fast reading method, they do match                    vert_offset = vert_offset + 3;                    //both #1 and #2 has the same data right?                    //data from #2 (vertices) is used in this draw method, but it doesn't draw it correctly                    drawFromData();



//fast read method            FileStream fs = new FileStream("rewritten_file_for_faster_reading.bin", FileMode.Open);            BinaryReader br = new BinaryReader(fs);            int x, y, z, color;            int i = 0;            do            {                x = br.ReadInt32();                y = br.ReadInt32();                z = br.ReadInt32();                color = br.ReadInt32();                vertices.Position = new Vector3(x, y, z);                vertices.Color = color;                //I output the vertices dot X, Y and Z to see if they match with the slow reading method, they do match                i++;            } while (i < 3000); // doesn't matter how much, just enough so we see some results             fs.Close();            br.Close();                        //call the same method as above, but filled from the new binary file. It draws correctly.            drawFromData();


//draw method that both slow and fast methods use after they fill in the vertices with dataprivate void drawFromData()        {            device.Clear(ClearFlags.Target, Color.White, 1.0f, 0);            device.Transform.Projection = Matrix.PerspectiveFovRH(fieldOfView, aspectRatio, 1f, 100000000f);            device.Transform.View = Matrix.LookAtRH(vCameraPos, vTarget, vUp);                        device.BeginScene();            device.VertexFormat = CustomVertex.PositionColored.Format;            device.DrawUserPrimitives(PrimitiveType.TriangleList, 1000, vertices); // again doesn't matter how much we draw, just so we see some results            device.EndScene();            device.Present();            this.Invalidate();        }
markookram
markookram
Maybe the only difference is the color? Hmm...
markookram
markookram
Yes it was the *beep*ing color! And I've been looking at the vertices...*beep*!

Topic Locked

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

Sign in to reply to this topic.