Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8330735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:12:23+00:00 2026-06-09T02:12:23+00:00

At last I have something displayed. Switched to using graphics.GraphicsDevice.DrawIndexedPrimitives … Next problem… Only

  • 0

At last I have something displayed. Switched to using graphics.GraphicsDevice.DrawIndexedPrimitives … Next problem… Only one triangle is displayed. The data set is about 200 triangles. I formatted the data coming in to make sure every three consecutive vectors form a triangle face. These are irregular triangles forming an irregular shape. I don’t fully understand the indexing of the vertices. Looks like each 3 indices form a triangle. If that is so then the indices match the data coming in. I did this:

int i4 = -1;
        indices = new int[xData1.Count];
        for (int i2 = 0; i2 < xData1.Count; i2++)
        {
            i4++;
            cubeVertices[i4].Position = new Vector3((float)xData1[i2][0], (float)xData1[i2][1], (float)xData1[i2][2]);
            cubeVertices[i4].Color = Color.LawnGreen;
            indices[i4] = i4;
        }

making the indices match the vertices coming in.. then I used Reimers normal calc to provide normals.. this is probably wrong as his example was using 6 vertices per index (I think!), like this:

for (int i = 0; i < cubeVertices.Length; i++)
            cubeVertices[i].Normal = new Vector3(0, 0, 0);

        for (int i = 0; i < indices.Length / 3; i++)
        {
            int index1 = indices[i * 3];
            int index2 = indices[i * 3 + 1];
            int index3 = indices[i * 3 + 2];

            Vector3 side1 = cubeVertices[index1].Position - cubeVertices[index3].Position;
            Vector3 side2 = cubeVertices[index1].Position - cubeVertices[index2].Position;
            Vector3 normal = Vector3.Cross(side1, side2);

            cubeVertices[index1].Normal += normal;
            cubeVertices[index2].Normal += normal;
            cubeVertices[index3].Normal += normal;
        }

        for (int i = 0; i < cubeVertices.Length; i++)
            cubeVertices[i].Normal.Normalize();

how many things do I need to fix here? I am only seeing 1 out of a couple of hundred triangles
🙁
thx for your patience

public struct VertexPositionColorNormal
    {
        public Vector3 Position;
        public Color Color;
        public Vector3 Normal;

        public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
        (
            new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
            new VertexElement(sizeof(float) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0),
            new VertexElement(sizeof(float) * 3 + 4, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0)
        );
    }

…

private void CopyToBuffers()
    {
        vertexBuffer = new VertexBuffer(graphics.GraphicsDevice, VertexPositionColorNormal.VertexDeclaration, 
            cubeVertices.Length, BufferUsage.WriteOnly);
        vertexBuffer.SetData(cubeVertices);

        myIndexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(int), indices.Length, BufferUsage.WriteOnly);
        myIndexBuffer.SetData(indices);
    }

….

foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
        {
            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = proj;

            pass.Apply();

            graphics.GraphicsDevice.Indices = myIndexBuffer;
            graphics.GraphicsDevice.SetVertexBuffer(vertexBuffer);
            graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
                cubeVertices.Length, 0, indices.Length / 3);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:12:24+00:00Added an answer on June 9, 2026 at 2:12 am

    Your normal calculation is correct, and even if it was wrong the only thing that would happen is that your triangles would receive the wrong lightning.

    You’re using indices which exactly match the order of the vertices coming in, which is in itself redundant. If you switch to not setting the indices at all and use DrawPrimitives instead with the primitive count the same does that make a difference?

    Other than that, are you sure that the data you’re giving it is valid? Are the vertex positions correctly set?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This was working last night, but I must have accidentally changed something, because it
Last night I tried to put together something that I have had working since
I want to have on my page something like This page last refreshed on:
I have spent last 3 days until I got gps working on android using
The last months I have tried to get started with web developing using Java.
I have installed last version 853.20120605-0921 of ExtLib... In designer I don't see under
Last day I have been interviewed and the interviewer asked me a) what is
In some measure of progress since my last question I have got the following
I have an application that uses OAuth whose logic is something like this: If
I have been developing a project in python for the last six months, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.