Author Topic: Vertex mesh manipulation question relating to structure of a plane vertex array  (Read 2018 times)

Offline davec64

  • byte
  • *
  • Posts: 31
    • View Profile
Hi
I have just spent a couple of days looking for bug in my code to finally work out it is not a bug but how the plane mesh is structured.
Here is what I think I have found by trial and error.
The first row of the mesh contains double the normal data of a normal row?
Writing the same data twice works for this case ie  dest[i++].z twice if row = 0
The array I have created is 174 *174
but the length comes back 30625 not 30276 as expected.
So it is 175 *175
So I assume I need to also add another duplicate point per row in the mesh. but where?
Any help gratefully received trail and error is to time consuming.
Thanks  code attached from my controller apply code 
Dave
Code: [Select]

 SimpleVector[] d = getDestinationMesh();
 i=0;
 int length = d.length;
 for (y = 0; y <= VesselRenderer.PANELSIZE; y++) {
      for (x = 0; x <= VesselRenderer.PANELSIZE; x++) {

        float data = (float) getData(x + VesselRenderer.m_panelxoffset, y
            + VesselRenderer.m_panelyoffset);
        // because I do not know where else to duplicate check length and do not go out of array bounds
        if (i < length) {
          d[i++].z = data;

          if (y == 0)
            d[i++].z = data;
        }
      }

    }


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
The controller works on vertices, not on polygons. Your calculation of the array length is based on quads. By default, jPCT uses indexed geometry, i.e. tries to merge vertices that share the same space. The number of polygons (two per quad) that share a vertex isn't the same for each vertex. The vertices at the edges are used by less polygons than the ones inside the plane. In your calculation, you assume that each new quad adds one new vertex to the index, which isn't true for the egdes. That's why the array differs from what you expected it to be. Anyway, i don't see the reason why you are working on the array in the way you do. Why don't you simply walk through it from 0 to length instead of working with x and y?

Offline davec64

  • byte
  • *
  • Posts: 31
    • View Profile
My panel is a partial window into a huge 3900*2000 map of which each point contains a depth, each tile in the map  that contains  uniuqe data is 348*348 this size is the optimum size. They are placed into a 5*10 grid.
If try to create a panel the same size as the tile the task just takes to long and never seems to return (allocating lots of memory).
So my initial attempt failed so I reduced the panel down until it worked.
Any recommendations gladly considered.
So now I scroll the panel and then refresh it when new data is required. That works quite well.
The x and y are just pointers into my data set.
So when  y is 0 I then write to 2 vertex locations. E.g. top edge. So which other edges require special treatment.
I just need to know where there will be 2 vertices representing one coord so to speak.
For instance my array is 174*174
The first 384 values in the mesh represent the top edge.
So where are they other duplicates. Left edge or right edge both ?
Does the last line of their panel also require 2 vertices. I have not observed this.
Just my panel data appears scewed.
Thanks for your help.
One other question is it possible to change the color of each vertex simply?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
One other question is it possible to change the color of each vertex simply?
No. It can be done by using a custom shader but that's not what i would consider simple.

About the duplicates...there aren't any "duplicates", but i think i know what you mean. I would expect them top, down and maybe one on each edge!? I'm not sure, it depends on the mesh and the way the index is being created. If you want to, you can print out the current position of each vertex. That should give you a feel of how they are organized.

Offline davec64

  • byte
  • *
  • Posts: 31
    • View Profile
  Solved :) :) :)
Code: [Select]
  if (i < length) {
          d[i++].z = data;
        }
        if (i < length - 2) {
          // if d[i].x  equals the last vector write the vector again.
          if (d[i - 1].x == d[i].x)
            d[i++].z = data;
        }
« Last Edit: November 25, 2013, 10:51:31 pm by davec64 »