• 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
Anand Baumunk

world matrix problem

7 posts in this topic

Hello guys, im getting a pretty wierd problem.
When I try to move my model by changing its worldmatrix, it gets draw some frames at the 0 0 0 position, and some other frams as totally messed up something. Same for rotation, but scaling works fine.

[source lang="cpp"]
D3DXMatrixIdentity(&World);
D3DXVECTOR3 rotaxisX = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
D3DXVECTOR3 rotaxisY = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
D3DXVECTOR3 rotaxisZ = D3DXVECTOR3(0.0f, 0.0f, 1.0f);

D3DXMATRIX temprot1, temprot2, temprot3;
D3DXMatrixRotationAxis(&temprot1, &rotaxisX, 0);
D3DXMatrixRotationAxis(&temprot2, &rotaxisY, 0);
D3DXMatrixRotationAxis(&temprot3, &rotaxisZ, 0);

Rotation = temprot1 *temprot2 * temprot3;


D3DXMatrixTranslation(&Translation, 0.0f, 10.0f, 0.0f);
D3DXMatrixScaling(&Scale, 0.02f, 0.02f, 0.02f);
//Set objs world space using the transformations
World = Translation * Rotation * Scale;
[/source]


Shader looks like this:


[source lang="cpp"]cbuffer cbPerObject
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
};

// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;

// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);
[/source]

I really cant see what is going wrong here. If all matrixchanges are 0, then its drawn fine.
Has it something to do with the math? The constantbuffer is set fine thought, light is set the same way and it works fine.

It looks like this (switching between these two frames randomly, ignore the terrain):
[url="http://imageshack.us/photo/my-images/3/32408839.png/"]http://imageshack.us...3/32408839.png/[/url]
[url="http://imageshack.us/photo/my-images/42/failjf.png/"]http://imageshack.us.../42/failjf.png/[/url] Edited by gnomgrol
0

Share this post


Link to post
Share on other sites
one thing I notice is that you do "World = Translate * Rotate * Scale", and in the shader "output.position = input.position * World". As a result, you first translate the point, then rotate it about the origin, and then scale it w.r.t the origin. It's more conventional to first scale, then rotate and finally translate, so try changing the code to "World = Scale * Rotate * Translate".
0

Share this post


Link to post
Share on other sites
Thank you, but that didnt do any good =(
The object now gets some times drawn in the right position, but the wierd flickering didnt change. Edited by gnomgrol
0

Share this post


Link to post
Share on other sites
When I encounter issues like this, my first go-to is PIX (and more recently, nVidia Paraller nSight). It's very helpful in disassembling the device state for evaluating that everything is as you'd expect.
0

Share this post


Link to post
Share on other sites
Well, I AM currently trying to figure out the problem with PIX myself, but I really cant see where the problem lies ..
I added two pictures to my first post.

Edit: Im through with analysing the buffers in PIX. I still cant see what the problem is, everything seems to be just fine.... Edited by gnomgrol
0

Share this post


Link to post
Share on other sites
Perhaps you're accidentally transposing some of the matrices, and you end up processing the translation elements of the matrix to affect the .w component of the output. This bug causes results that look a bit like the second image - vertices flying towards "infinity" in one direction.
0

Share this post


Link to post
Share on other sites
You are right. When I delete the line that transposes the worldmatrix, it keeps looking like pic2. Now I need to figure why the matrix only gets transposed in some frames, while in others not. Here is the drawingcode:

[CODE]
D3DXMatrixTranspose(&World, &World);
D3DXMatrixTranspose(&camView, &camView);
D3DXMatrixTranspose(&camProjection, &camProjection);
// Lock the constant buffer so it can be written to.
D3D11_MAPPED_SUBRESOURCE mappedResource;
d3d11DevCon->Map(matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
cbPerObject* dataPtr;
dataPtr = (cbPerObject*)mappedResource.pData;
// Copy the matrices into the constant buffer.
dataPtr->worldMatrix = World;
dataPtr->viewMatrix = camView;
dataPtr->projectionMatrix = camProjection;
// Unlock the constant buffer.
d3d11DevCon->Unmap(matrixBuffer, 0);
d3d11DevCon->VSSetConstantBuffers(0, 1, &matrixBuffer);
[/CODE]
0

Share this post


Link to post
Share on other sites
I fixed it, but I dont know what caused it exactly. I have to call this code EVERY frame, not only once (I have no idea why)
[source lang="cpp"]D3DXMatrixIdentity(&World);
D3DXVECTOR3 rotaxisX = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
D3DXVECTOR3 rotaxisY = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
D3DXVECTOR3 rotaxisZ = D3DXVECTOR3(0.0f, 0.0f, 1.0f);

D3DXMATRIX temprot1, temprot2, temprot3;
D3DXMatrixRotationAxis(&temprot1, &rotaxisX, 0);
D3DXMatrixRotationAxis(&temprot2, &rotaxisY, 0);
D3DXMatrixRotationAxis(&temprot3, &rotaxisZ, 0);

Rotation = temprot1 *temprot2 * temprot3;


D3DXMatrixTranslation(&Translation, 0.0f, 10.0f, 0.0f);
D3DXMatrixScaling(&Scale, 0.02f, 0.02f, 0.02f);
//Set objs world space using the transformations
World = Scale * Rotation * Translation;[/source]

Now it works, but can you tell me why? Edited by gnomgrol
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