• 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

Rotating triangle

3 posts in this topic

Hello forum, sorry for a noob question, I know it's a basic stuff and all that. So I have read some tutorials about basics of DX and found some complete code to draw lines, rectangles, circles, text.., combined it in my own class and it works pretty well. But I can't get how to draw triangles using primitives. I have found some code, but one problem is that I can't rotate it. Here is the code I've found:


    FLOAT x, y, z, rhw;    // from the D3DFVF_XYZRHW flag
    DWORD tColor;    // from the D3DFVF_DIFFUSE flag

HRESULT DrawFilledTriangleEx( FLOAT PosX, FLOAT PosY, FLOAT Size, DWORD tColourStart, DWORD tColourMid, DWORD tColourEnd, IDirect3DDevice9* Dev )

pLine[0].x      = PosX;
pLine[0].y      = PosY;
pLine[0].z      = 1.0f;
pLine[0].rhw    = 1.0f;
pLine[0].tColor = tColourStart;

pLine[1].x      = PosX + Size;
pLine[1].y      = PosY;
pLine[1].z      = 0.0f;
pLine[1].rhw    = 1.0f;
pLine[1].tColor = tColourMid;

pLine[2].x      = PosX;
pLine[2].y      = PosY + Size;
pLine[2].z      = 0.0f;
pLine[2].rhw    = 1.0f;
pLine[2].tColor = tColourEnd;


Dev->GetFVF( &dwFvF );

hRet = Dev->DrawPrimitiveUP( D3DPT_TRIANGLELIST, 3, pLine, sizeof(CUSTOMVERTEX) ); 

Dev->SetFVF( dwFvF );

return hRet;

Here is the result of a function : here


So on the screen red triangle is what I got after DrawFilledTriangleEx call, white is what I want to get. I've tried to play with function code, but triangle just disappears quickly. I know I should spend the time on reading or find something different to do,  but seriously everything I was able to find in examples it's just one colored triangle and no information on how to setup it's size or angle. Please sorry one more time.




Share this post

Link to post
Share on other sites

If I remember correctly from OpenGl you apply transformations before you draw the triangle.


I hope people will correct me if I am wrong, but it seems as if you modify a matrix with ...

D3DXMatrixRotationX(...), D3DXMatrixRotationY(...), D3DXMatrixRotationZ(...)


and then apply it with ...






or D3DXMatrixRotationYawPitchRoll(&matRotate, ry, rx, rz);!?

There is an article:





I'd expect the transformation outside the drawing function for the triangle ...

Edited by DareDeveloper

Share this post

Link to post
Share on other sites

It appears you're confusing terms. You use D3DPT_TRIANGLELIST in your draw call and you do, indeed, get a filled triangle. If you want to draw lines (which is what the white object in the image appears to be comprised of), you may want to read the docs and look at D3DPT_LINELIST. IIRC, you'll get lines 1 pixel in width.


As DareDeveloper mentions, you should create your vertex array just once somewhere and reuse it for rendering. As you've coded it, you create the array, fill it, render it and delete it (when the function returns), every time the draw function is called.

Edited by Buckeye

Share this post

Link to post
Share on other sites

One problem you'll have applying a rotation transform is that your triangle is defined with its world positions directly in the buffer. You need to have an object relative to its rotational centre for the rotation matrix to apply properly.


In other words, define the triangle in the vertex buffer relative to its own centre. Then create a rotation transform and also a translation transform (D3DXMatrixTranslation) that moves it to the right place. Then create your world transform by multiplying the rotation transform by the translation transform (order is important) to first rotate the triangle round its centre, then move it to its world position.


It is really, really worth spending some time studying matrix stuff at a high level i.e. not how they work but how you use them.

Edited by Aardvajk

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