• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MatsK

Mesh with relative coordinates

1 post in this topic

[font=Verdana, sans-serif]Hey, I'm trying to render a mesh format where the vertices aren't stored with their actual coordinates in the file.[/font]
[font=Verdana, sans-serif]Here's the explanation I got:[/font]

[code]in a mesh, vertices are stored as coordinates relative to the proximal end of the bone that they're attached to.
so you need to walk down the bone tree, and then for each vertex, rather than plotting it, move the camera to that position and obtain the absolute position of the camera, and then move back.
now you can store that position in the TransformedVertices array.
do that for both the fixed and blended vertices
then once the array is completely filled up, blend the blended vertices towards their fixed vertices that they're influenced by.
then you can draw all the faces for that mesh, and all the vertices will be in the right spots.[/code]

[font=Verdana, sans-serif]Here's my attempt to do the above:[/font]

[font=Verdana, sans-serif][code]public void TransformVertices2(Skeleton Skel)
{
float[,] LocalCopy;
foreach (Bone Bne in Skel.Bones)
{
foreach (BoneBinding BBinding in m_BoneBindings)
{
if (BBinding.BoneIndex == Bne.ID)
{
if (BBinding.FirstVertex != -1)
{
int VertexCount = 0;
if (BBinding.FirstVertex > BBinding.VertexCount)
VertexCount = BBinding.FirstVertex - BBinding.VertexCount;
else
VertexCount = BBinding.VertexCount - BBinding.FirstVertex;[/font]
LocalCopy = new float[VertexCount, 6];
Array.Copy(m_VertexData, BBinding.FirstVertex, LocalCopy, 0, VertexCount);[/font]
for (int i = 0; i < VertexCount; i++)
{
//The below is from: http://msdn.microsoft.com/en-us/library/bb197901.aspx
//Calculate the camera's current position.[/font]
//Set the direction the camera points without rotation.
Vector3 CameraReference = Bne.GlobalTranslation;
//Camera's position.
Vector3 CameraPos = new Vector3(LocalCopy[i, 0], LocalCopy[i, 1], LocalCopy[i, 2]);[/font]
Matrix RotationMatrix = Matrix.CreateFromQuaternion(Bne.GlobalRotation);
//Create a vector pointing the direction the camera is facing.
Vector3 TransformedReference = Vector3.Transform(CameraReference, RotationMatrix);
//Calculate the position the camera is looking at.
Vector3 CameraLookat = CameraPos + TransformedReference;[/font]
m_TransformedVertices[i] = CameraLookat;
}
}
if (BBinding.FirstBlendedVert != -1)
{
int BlendedVertexCount = 0;
if (BBinding.FirstBlendedVert > BBinding.BlendedVertexCount)
BlendedVertexCount = BBinding.FirstBlendedVert - BBinding.BlendedVertexCount;
else
BlendedVertexCount = BBinding.BlendedVertexCount - BBinding.FirstBlendedVert;[/font]
LocalCopy = new float[BlendedVertexCount, 6];
Array.Copy(m_VertexData, BBinding.FirstBlendedVert, LocalCopy, 0, BlendedVertexCount);[/font]
for (int j = 0; j < BlendedVertexCount; j++)
{
//The below is from: http://msdn.microsoft.com/en-us/library/bb197901.aspx
//Calculate the camera's current position.[/font]
//Set the direction the camera points without rotation.
Vector3 CameraReference = Bne.GlobalTranslation;
//Camera's position.
Vector3 CameraPos = new Vector3(LocalCopy[j, 0], LocalCopy[j, 1], LocalCopy[j, 2]);[/font]
Matrix RotationMatrix = Matrix.CreateFromQuaternion(Bne.GlobalRotation);
//Create a vector pointing the direction the camera is facing.
Vector3 TransformedReference = Vector3.Transform(CameraReference, RotationMatrix);
//Calculate the position the camera is looking at.
Vector3 CameraLookat = CameraPos + TransformedReference;[/font]
m_TransformedVertices[j] = CameraLookat;
}
}
}
}
}
}[/code][/font]





[font=Verdana, sans-serif]Problem is, this doesn't work! [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img][/font]
[font=Verdana, sans-serif]Can someone please explain how to implement this algorithm in XNA?[/font]




[font=Verdana, sans-serif]Here's my rendering code:[/font]





[font=Verdana, sans-serif][code]private void mWinForm_OnFrameRender(GraphicsDevice pDevice)
{
/*m_SBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.SaveState);

m_SBatch.Draw(m_BackgroundTex, new Microsoft.Xna.Framework.Rectangle(0, 0, m_BackgroundTex.Width,
m_BackgroundTex.Height), Microsoft.Xna.Framework.Graphics.Color.White);

m_SBatch.End();*/

Device.RenderState.DepthBufferEnable = true;
Device.RenderState.DepthBufferWriteEnable = true;
Device.RenderState.AlphaBlendEnable = false;

// Configure effect
mSimpleEffect.World = this.mWorldMat;
mSimpleEffect.View = this.mViewMat;
mSimpleEffect.Projection = this.mProjectionMat;

if (m_Tex != null)
{
mSimpleEffect.Texture = m_Tex;
mSimpleEffect.TextureEnabled = true;

//Disable lights in an attempt to render bodies...
//mSimpleEffect.EnableDefaultLighting();
}

mSimpleEffect.CommitChanges();

// Draw
mSimpleEffect.Begin();
mSimpleEffect.Techniques[0].Passes[0].Begin();

if (m_NormVerticies != null)
{
if (m_LoadComplete)
{
if (m_CurrentMesh.IsBodyMesh)
{
//m_MatrixStack.Push(mSimpleEffect.World);
//glLoadIdentity();
//mSimpleEffect.View = Matrix.Identity;

m_CurrentMesh.TransformVertices2(m_Skeleton);

//mSimpleEffect.View = m_MatrixStack.Pop();

m_CurrentMesh.BlendVertices2();
}

foreach (Face Fce in m_CurrentMesh.Faces)
{
VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
Vertex[0] = m_NormVerticies[Fce.AVertexIndex];
Vertex[1] = m_NormVerticies[Fce.BVertexIndex];
Vertex[2] = m_NormVerticies[Fce.CVertexIndex];

Vertex[0].TextureCoordinate = m_NormVerticies[Fce.AVertexIndex].TextureCoordinate;
Vertex[1].TextureCoordinate = m_NormVerticies[Fce.BVertexIndex].TextureCoordinate;
Vertex[2].TextureCoordinate = m_NormVerticies[Fce.CVertexIndex].TextureCoordinate;

pDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
Vertex, 0, 1);
}
}
}

mSimpleEffect.Techniques[0].Passes[0].End();
mSimpleEffect.End();

}[/code][/font]
0

Share this post


Link to post
Share on other sites
Ok, so I tried a slightly different approach;

[code]

public void TransformVertices2(Bone Bne, ref BasicEffect Effect)
{
int BoneIndex = 0;

Matrix WorldMat = Matrix.CreateWorld(Bne.GlobalTranslation, Vector3.Forward, Vector3.Up);

//glMultMatrixf()
WorldMat *= Matrix.CreateFromQuaternion(Bne.GlobalRotation);

Effect.World = WorldMat;

for (BoneIndex = 0; BoneIndex < m_BndCount; BoneIndex++)
{
if (Bne.BoneName == m_BoneNames[m_BoneBindings[BoneIndex].BoneIndex])
break;
}

if (BoneIndex < m_BndCount)
{
for (int i = 0; i < m_BoneBindings[BoneIndex].VertexCount; i++)
{
uint VertexIndex = (uint)(m_BoneBindings[BoneIndex].FirstVertex + i);

Vector3 RelativeVertex = new Vector3(m_VertexData[VertexIndex, 0], m_VertexData[VertexIndex, 1],
m_VertexData[VertexIndex, 2]);

//Move the world and view to the relative position of the current vertex.
WorldMat = Matrix.CreateWorld(RelativeVertex, Vector3.Forward, Vector3.Up);
Effect.World = WorldMat;
Effect.View = WorldMat;

//Get the absolute position of the current vertex.
m_TransformedVertices[VertexIndex].X = WorldMat.M34;
m_TransformedVertices[VertexIndex].Y = WorldMat.M41;
m_TransformedVertices[VertexIndex].Z = WorldMat.M42;

//Move back.
WorldMat *= Matrix.CreateWorld(new Vector3(-RelativeVertex.X, -RelativeVertex.Y, -RelativeVertex.Z),
Vector3.Forward, Vector3.Up);
Effect.World = WorldMat;
Effect.View = WorldMat;
}

for (int i = 0; i < m_BoneBindings[BoneIndex].BlendedVertexCount; i++)
{
uint VertexIndex = (uint)(m_NumFixedVerticies + m_BoneBindings[BoneIndex].FirstBlendedVert + i);

Vector3 RelativeVertex = new Vector3(m_VertexData[VertexIndex, 0], m_VertexData[VertexIndex, 1],
m_VertexData[VertexIndex, 2]);

//Move the world and view to the relative position of the current vertex.
WorldMat = Matrix.CreateWorld(RelativeVertex, Vector3.Forward, Vector3.Up);
Effect.World = WorldMat;
Effect.View = WorldMat;

//Get the absolute position of the current vertex.
m_TransformedVertices[VertexIndex].X = WorldMat.M34;
m_TransformedVertices[VertexIndex].Y = WorldMat.M41;
m_TransformedVertices[VertexIndex].Z = WorldMat.M42;

//Move back.
WorldMat *= Matrix.CreateWorld(new Vector3(-RelativeVertex.X, -RelativeVertex.Y, -RelativeVertex.Z),
Vector3.Forward, Vector3.Up);
Effect.World = WorldMat;
Effect.View = WorldMat;
}
}

if (Bne.Children.Count == 1)
TransformVertices2(Bne.Children[0], ref Effect);
else if (Bne.Children.Count > 1)
{
for (int i = 0; i < Bne.Children.Count; i++)
TransformVertices2(Bne.Children[i], ref Effect);
}
}[/code]

[code] public void BlendVertices2()
{
for (int i = 0; i < m_BlendCount; i++)
{
float Weight = m_BlendData[i].WeightFixed;

Vector3 BlendedVertex = m_TransformedVertices[m_NumFixedVerticies + i];
Vector3 FixedVertex = m_TransformedVertices[m_NumFixedVerticies + i];

BlendedVertex.X = Weight * BlendedVertex.X + (1 - Weight) * FixedVertex.X;
BlendedVertex.Y = Weight * BlendedVertex.X + (1 - Weight) * FixedVertex.Y;
BlendedVertex.Z = Weight * BlendedVertex.X + (1 - Weight) * FixedVertex.Z;

m_TransformedVertices[m_NumFixedVerticies + i] = BlendedVertex;
}
}[/code]

This nearly works, but all the vertices are laid out on the same plane! Why?

[IMG]http://i40.tinypic.com/ived1z.png[/IMG]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0