public static unsafe void AccumulateNormals(int *pIndices, Point3D *pVertices, Point3D *pNormals, int indexCount, int vertexCount) { int *numPtr = pIndices + indexCount; while (pIndices < numPtr) { Point3D point3D1 = Point3D.Cross(pVertices[*pIndices], pVertices[pIndices[1]], pVertices[pIndices[2]]); IntPtr num1 = (IntPtr)(pNormals + *pIndices); Point3D point3D2 = *(Point3D *)num1 + point3D1; *(Point3D *)num1 = point3D2; IntPtr num2 = (IntPtr)(pNormals + pIndices[1]); Point3D point3D3 = *(Point3D *)num2 + point3D1; *(Point3D *)num2 = point3D3; IntPtr num3 = (IntPtr)(pNormals + pIndices[2]); Point3D point3D4 = *(Point3D *)num3 + point3D1; *(Point3D *)num3 = point3D4; pIndices += 3; } Point3D *point3DPtr = pNormals + vertexCount; while (pNormals < point3DPtr) { ++pNormals; } }
public unsafe IPointDataChunk Process(IPointDataChunk chunk) { byte *pb = chunk.PointDataPtr; while (pb < chunk.PointDataEndPtr) { Point3D *p = (Point3D *)pb; ++m_counts[(int)(((*p).Z - m_min) * m_intervalsOverRangeZ)]; pb += chunk.PointSizeBytes; } return(chunk); }
private unsafe void ComputeVerticesCore(float *pHeightmap, Point3D *pVertices, int divisions) { for (int index1 = 0; index1 <= divisions; ++index1) { for (int index2 = 0; index2 <= divisions; ++index2) { pVertices->X = 22 * (index2 - index1); pVertices->Y = 22 * (index2 + index1); pVertices->Z = (int)((double)(4 * divisions) * (double)*pHeightmap); ++pVertices; ++pHeightmap; } } }
private unsafe void ComputeNormals(float *pHeightmap) { int size = this._meshProvider.Size; int divisions = this._meshProvider.Divisions; Point3D *pVertices = stackalloc Point3D[size]; this.ComputeVerticesCore(pHeightmap, pVertices, divisions); fixed(Point3D *pNormals = this.AllocateNormals(size)) { int indexCount; fixed(int *pIndices = this.GetIndices(out indexCount)) MapLighting.AccumulateNormals(pIndices, pVertices, pNormals, indexCount, size); } }
static void Main(string[] args) { // Declare a point Point3D point; // Get a pointer to the point Point3D *pt = &point; pt->X = 0; pt->Y = 100; (*pt).Z = 200; // Print the values Console.WriteLine($"X is {pt->X}, Y is {pt->Y} and Z is {(*pt).Z}"); Console.Read(); }
public unsafe IPointDataChunk Process(IPointDataChunk chunk) { if (m_index + chunk.PointCount <= m_count) { byte *pb = chunk.PointDataPtr; if (m_quantized) { int[][] values = m_values as int[][]; while (pb < chunk.PointDataEndPtr) { SQuantizedPoint3D *p = (SQuantizedPoint3D *)pb; values[0][m_index] = (*p).X; values[1][m_index] = (*p).Y; values[2][m_index] = (*p).Z; ++m_index; pb += chunk.PointSizeBytes; } } else { double[][] values = m_values as double[][]; while (pb < chunk.PointDataEndPtr) { Point3D *p = (Point3D *)pb; values[0][m_index] = (*p).X; values[1][m_index] = (*p).Y; values[2][m_index] = (*p).Z; ++m_index; pb += chunk.PointSizeBytes; } } } return(chunk); }
public static ColorVertexes Create(int nx, int ny, int nz, float radius, float minValue, float maxValue) { int points = nx * ny * nz; ColorVertexes colorVertexes = new ColorVertexes(points); Random random = new Random(); Random colorRandom = new Random(); float xmin = 0, xmax = 0, ymin = 0, ymax = 0, zmin = 0, zmax = 0; bool isInit = false; unsafe { for (long i = 0; i < colorVertexes.Size; i++) { float x = minValue + ((float)random.NextDouble()) * maxValue; float y = minValue + ((float)random.NextDouble()) * maxValue; float z = minValue + ((float)random.NextDouble()) * maxValue; if (!isInit) { xmin = x; xmax = x; ymin = y; ymax = y; zmin = z; zmax = z; isInit = true; } if (x < xmin) { xmin = x; } if (x > xmax) { xmax = x; } if (y < ymin) { ymin = y; } if (y > ymax) { ymax = y; } if (z < zmin) { zmin = z; } if (z > zmax) { zmax = z; } Point3D *centers = colorVertexes.Centers; centers[i].x = x; centers[i].y = y; centers[i].z = z; Color *colors = colorVertexes.Colors; colors[i].red = (byte)colorRandom.Next(0, 256); colors[i].green = (byte)colorRandom.Next(0, 256); colors[i].blue = (byte)colorRandom.Next(0, 256); } Point3D location; location.x = xmin; location.y = ymin; location.z = zmin; Size3D size; size.x = (xmax - xmin); size.y = (ymax - ymin); size.z = (zmax - zmin); Rect3D rect = new Rect3D(location, size); colorVertexes.Bounds = rect; } return(colorVertexes); }