• 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
exextatic

[D3D9] 'Drawing' into window

15 posts in this topic

Hi all,

Working on a level editor for my engine (still), and I'm at a loss as to how I should go about this next bit.
I want to have the user click, drag and release to make a box (which will be turned into a plane - 2D engine).
I can't seem to get the mouse coordinates to relate to the position in the 3d view.
Heres an image just so you guys can see what I've currently got:
[img]http://i40.tinypic.com/sy3w2u.png[/img]
Note, it has 3D views because I want this editor to be re-usable in the future.

Any help appreciated,

Thanks,
James Warner
0

Share this post


Link to post
Share on other sites
In what way can you not get the mouse coordinates to relate to 3D positions? You can use D3DXVec3Unproject() to convert from screen space to world space.
0

Share this post


Link to post
Share on other sites
Okay fixed the rendering engine (finally).

Heres the code I have currently for adding planes:
[CODE]void Editor::addPlane(D3DXVECTOR3 oldMPos, D3DXVECTOR3 oldMDir, string texName, float* texScale, int whichForm)
{
D3DXMATRIX matView;
if(whichForm == 0)
{
fpsCamera->calculateViewMatrix(&matView);
cameraPos[whichForm] = fpsCamera->getPosition();
cameraEyePos[whichForm] = fpsCamera->getEyePos();
}
else
{
D3DXMatrixLookAtLH(&matView,
&cameraPos[whichForm],
&cameraEyePos[whichForm],
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));
}
d3ddev->SetTransform(D3DTS_VIEW, &matView);

D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),
(FLOAT)screenSize[whichForm].x / (FLOAT)screenSize[whichForm].y,
1.0f,
100.0f);
d3ddev->GetTransform(D3DTS_PROJECTION, &matProjection);


D3DXVECTOR3 finalPos, size, firstMDir = oldMPos, curMDir = pickRaysOrigin[whichForm];

//Get position
bool interpolatedOnY = false;
for(int i = 0; i < 100; i++)
{
if(firstMDir.y > 3.0f)
{
interpolatedOnY = true;
break;
}

firstMDir += oldMDir;
}

if(!interpolatedOnY)
return; // Wasn't available on Y axis - User managed to get Camera not to face right axis?

finalPos = firstMDir;
interpolatedOnY = false;

//Get size
for(int i = 0; i < 100; i++)
{
if(curMDir.y > 3.0f)
{
interpolatedOnY = true;
break;
}

curMDir += pickRaysDir[whichForm];
}

if(!interpolatedOnY)
return; // Wasn't available on Y axis - User managed to get Camera not to face right axis?

if(firstMDir > curMDir)
size = firstMDir - curMDir;
else
size = curMDir - firstMDir;

addPlane(D3DXVECTOR2(finalPos.x, finalPos.y), D3DXVECTOR2(size.x, size.y), 0.0f, PhysDefinition(NoPhysics, 0.0f, 0.0f, 0.0f), ForeGroundPlane, TextureDefinition(texName, D3DXVECTOR2(texScale[0], texScale[1]), 0.0f));
}[/CODE]
It just ends up in the entirely wrong place.
0

Share this post


Link to post
Share on other sites
[CODE]void Editor::addPlane(D3DXVECTOR3 oldMPos, D3DXVECTOR3 oldMDir, string texName, float* texScale, int whichForm)
{
D3DXMATRIX matView;
if(whichForm == 0)
{
fpsCamera->calculateViewMatrix(&matView);
cameraPos[whichForm] = fpsCamera->getPosition();
cameraEyePos[whichForm] = fpsCamera->getEyePos();
}
else
{
D3DXMatrixLookAtLH(&matView,
&cameraPos[whichForm],
&cameraEyePos[whichForm],
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));
}
d3ddev->SetTransform(D3DTS_VIEW, &matView);

D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),
(FLOAT)screenSize[whichForm].x / (FLOAT)screenSize[whichForm].y,
1.0f,
100.0f);
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);

POINT mousePos;
GetCursorPos(&mousePos);

D3DXVECTOR3 mouseOut, mouseOut2, mouseFinal;
D3DVIEWPORT9 viewPort;
D3DXMATRIX matWorld;

d3ddev->GetTransform(D3DTS_WORLD, &matWorld);
d3ddev->GetViewport(&viewPort);

ScreenToClient(hWnd[whichForm], &mousePos);

D3DXVec3Unproject(&mouseOut, &D3DXVECTOR3(mousePos.x, mousePos.y, viewPort.MinZ), &viewPort, &matProjection, &matView, &matWorld);
D3DXVec3Unproject(&mouseOut2, &D3DXVECTOR3(mousePos.x, mousePos.y, viewPort.MaxZ), &viewPort, &matProjection, &matView, &matWorld);

float wz = 3.0f;
float wx = ((wz - mouseOut.z) * (mouseOut2.x - mouseOut.x)) / (mouseOut2.z - mouseOut.z) + mouseOut.x;
float wy = ((wz - mouseOut.z) * (mouseOut2.y - mouseOut.y)) / (mouseOut2.z - mouseOut.z) + mouseOut.y;

mouseFinal = D3DXVECTOR3(wx, wy, wz);

addPlane(D3DXVECTOR2(mouseFinal.x, mouseFinal.y), D3DXVECTOR2(1.0f, 1.0f), 0.0f, PhysDefinition(NoPhysics, 0.0f, 0.0f, 0.0f), ForeGroundPlane, TextureDefinition(texName, D3DXVECTOR2(texScale[0], texScale[1]), 0.0f));
}[/CODE]
Thats my new code to try out (still not working, but slightly better). I would upload the editor files for you to see for your self, but my ISP has my internet connection capped down to 25KB/s for the next 2 days.
0

Share this post


Link to post
Share on other sites
I've uploaded the editor so you guys can see what happens (Make a new Map file, and right click on the bottom right hand render screen)
http://jameswarner.co.cc/Files/Other/Editor.rar
Heres what happens when I right click (on the red dot). I clicked a few times and it seems to alternate between the 2 different positions that the Planes spawn at.
[img]http://i41.tinypic.com/152l301.png[/img]
0

Share this post


Link to post
Share on other sites
I don't have time to look in-depth just now, but I'd suggest printing out the various coordinates fed in and out of your picking code to see why the position is flickering between two locations like that. If you can get it so that it's in one position, that'll make it easier to narrow down. Then, if it's still wrong by a fixed offset, check that the top left coordinate of the viewport is correct, that your input mouse coordinates are relative to the viewport and not in screen space, and so on.
1

Share this post


Link to post
Share on other sites
[quote name='Evil Steve' timestamp='1329833224' post='4915167']
I don't have time to look in-depth just now, but I'd suggest printing out the various coordinates fed in and out of your picking code to see why the position is flickering between two locations like that. If you can get it so that it's in one position, that'll make it easier to narrow down. Then, if it's still wrong by a fixed offset, check that the top left coordinate of the viewport is correct, that your input mouse coordinates are relative to the viewport and not in screen space, and so on.
[/quote]
Thats made me think, is there a viewport per-swapchain? Im just using GetViewport() to get a viewport, and using that in the D3DXVec3Unproject()
Also, I think I've fixed it from flickering between places (restores the world matrix from when the app started instead of using the current world matrix).
Its still off from the mouse position though.
0

Share this post


Link to post
Share on other sites
Ok, gonna post some more code and upload the latest version for you guys..
Heres the picking code at the moment:</p>
[CODE]void Editor::addPlane(D3DXVECTOR3 oldMPos, D3DXVECTOR3 oldMDir, string texName, float* texScale, int whichForm)
{
D3DXMATRIX matView, matWorld;
d3ddev->SetTransform(D3DTS_WORLD, &matStart);
matWorld = matStart;

if(whichForm == 0)
{
fpsCamera->calculateViewMatrix(&matView);
cameraPos[whichForm] = fpsCamera->getPosition();
cameraEyePos[whichForm] = fpsCamera->getEyePos();
}
else
{</div>
D3DXMatrixLookAtLH(&amp;matView,
&cameraPos[whichForm],
&cameraEyePos[whichForm],
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));
}
d3ddev->SetTransform(D3DTS_VIEW, &matView);

D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&amp;matProjection,
D3DXToRadian(45),
(FLOAT)screenSize[whichForm].x / (FLOAT)screenSize[whichForm].y,
1.0f,
100.0f);
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);

POINT mousePos;
GetCursorPos(&mousePos);

D3DXVECTOR3 mouseOut, mouseOut2;
D3DVIEWPORT9 viewPort;

d3ddev->GetViewport(&viewPort);

ScreenToClient(hWnd[whichForm], &mousePos);

D3DXVec3Unproject(&mouseOut, &D3DXVECTOR3(mousePos.x, mousePos.y, viewPort.MinZ), &viewPort, &matProjection, &matView, &matWorld);
D3DXVec3Unproject(&mouseOut2, &D3DXVECTOR3(mousePos.x, mousePos.y, viewPort.MaxZ), &viewPort, &matProjection, &matView, &matWorld);

float wz = 3.0f;
float wx = ((wz - mouseOut.z) * (mouseOut2.x - mouseOut.x)) / (mouseOut2.z - mouseOut.z) + mouseOut.x;
float wy = ((wz - mouseOut.z) * (mouseOut2.y - mouseOut.y)) / (mouseOut2.z - mouseOut.z) + mouseOut.y;
D3DXVECTOR3 mouseFinal = D3DXVECTOR3(wx, wy, wz);

addPlane(D3DXVECTOR2(mouseFinal.x, mouseFinal.y), D3DXVECTOR2(1.0f, 1.0f), 0.0f, PhysDefinition(NoPhysics, 0.0f, 0.0f, 0.0f), ForeGroundPlane, TextureDefinition(texName, D3DXVECTOR2(texScale[0], texScale[1]), 0.0f));
}[/CODE]
Heres the latest build:
[url="http://jameswarner.co.cc/Files/Other/Editor.rar"]http://jameswarner.co.cc/Files/Other/Editor.rar[/url]
And heres whats happening currently:
[img]http://i44.tinypic.com/33mmjwo.png[/img]

Any ideas?
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