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

  • SEARCH
  • Home
  • 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 8054463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:09:28+00:00 2026-06-05T08:09:28+00:00

I have a Block class that basically contains an array of 36 vertices, a

  • 0

I have a Block class that basically contains an array of 36 vertices, a constructor that builds the block around the origin (0, 0, 0), and a method for updating.

I’m using a Physics library to manipulate the blocks. I assign a body and collision skin to the block and update the physics step every update. After every update I get a matrix back with the block’s new position, orientation, etc.

Now, what I can’t wrap my head around is the best way to go about applying the matrix to the block and efficiently updating the vertex buffer every frame.

This is basically what I have at the moment, I’m almost positive there’s a better method…

class Block
{
    const float FullBlockSize = 20f;
    const float HalfBlockSize = FullBlockSize / 2;

    public VertexPositionNormalTexture [] vertices = new VertexPositionNormalTexture[36];
    public VertexPositionNormalTexture [] currentVertices = new VertexPositionNormalTexture[36];
    public DynamicVertexBuffer vBuffer;

    Vector3 position;

    public Block(Vector3 blockPosition)
    {
        position = blockPosition * FullBlockSize;

        /*
         * Build the 6 faces of the block here.
         * The block is built around the origin,
         * (0, 0, 0) being the center of the block.
        */

        vBuffer = new DynamicVertexBuffer(Game.Device, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
        vBuffer.SetData(vertices);
    }
    public Matrix WorldMatrix
    {
        get
        {
            return Matrix.CreateTranslation(position);
        }
    }
    public void Update()
    {
        currentVertices = (VertexPositionNormalTexture[])vertices.Clone();
        Matrix currentWorld = WorldMatrix;
        for(int i = 0; i < currentVertices.Length; ++i)
        {
            currentVertices[i].Position = Vector3.Transform(currentVertices[i].Position, currentWorld);
        }
        vBuffer.SetData(currentVertices);
    }
}
  • 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-05T08:09:30+00:00Added an answer on June 5, 2026 at 8:09 am

    Let the shader do it…one of the parameters of a shader is usually a WorldMatrix…

    to draw it:

    effect.Parameters["WorldMatrix"].SetValue(World);
    effect.Apply(0);
    

    if you have problems drawing a block… try to create a world transform matrix by yourself and test it…

    effect.Parameters["WorldMatrix"].SetValue(Matrix.CreateRotationZ(angle));
    effect.Apply(0);
    

    If you have several instances of block, you can use instancing to pass the trasnform matrix in a vertexBuffer to the shader…

    Here you can find info about instancing: http://blogs.msdn.com/b/shawnhar/archive/2010/06/17/drawinstancedprimitives-in-xna-game-studio-4-0.aspx

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

Sidebar

Related Questions

Basically, I have a block of memory allocated using malloc that I want to
The Situation I have a table in a DB that contains job types, basically
I have a class that manages the creation of RTF documents and a method
I have a block of code that basically intializes several classes, but they are
I have a UserControl that contains an Expander : <UserControl x:Class=Client.DevicesExpander xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
I have several blocks that look like this: <div class='templatechoicedesigncss'> <img src='/images/templatepics/random(100x140).png' /> <p>
Hi I have following code block public class Driver { static String x =
I have a class in which i have intialized hashmap in static block. Passing
I have a block element (DIV) who stretches across an entire page. It contains
I have a block of text that im taking from a Gedcom ( Here

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.