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

Rotate object to face other object

5 posts in this topic

hi i have some problems to correctly rotate a cube to the other.

i have one cube that i can move and i need the other cube to rotate in his direction  when its moving

when run program, the cube rotates some in the dircection  but when i go behind or under it changes direction.

 

i think it has somthing to do whit the direction of the cube ,or the angle or the rotation direction

 

this is the code dat i update:

 

translationform1 =XMVectorSet (xaxis1, 0.0f, zaxis1,0.0f);
    cube1transform = XMVectorSet(3.0f, 0.0f, 4.5f, 0.0f);
    cube2transform = XMVectorSet(-5.0f , 0.0f, 4.5f, 0.0f);
    directioncube = cube1transform - cube2transform;
    
    cubetranslation1 = D3DXVECTOR3(xaxis1, 0.0f, zaxis1);
    cubelocation1 = D3DXVECTOR3(3.0f, 0.0f, 4.5f);
    cube2position = D3DXVECTOR3(-5.0f, 0.0f, 4.5f);


    cubeposition = cube1transform + translationform1;
    cubepos1 = cubelocation1 + cubetranslation1;

    cubeoldpos = cubepos1 - cubetranslation1;

*//direction2=0.0f,0.0f,1.0f)

    direction2 = direction2;        // i also tried cubeoldposition-cube2position  "to get the new direction whit eache update"..
    direction1 = cubepos1 - cube2position;

    D3DXVec3Normalize(&direction2Norm, &direction2);
    D3DXVec3Normalize(&direction1Norm, &direction1);
    directioncubeNorm = XMVector3Normalize(directioncube);


    renderrotate = D3DXVec3Dot(&direction1Norm, &direction2Norm);
    dot = renderrotate;
    renderrotate = (acos(renderrotate));


    if (dot < 0)
        renderrotate *=-1;

    else
    renderrotate *=1;




    rotation = XMMatrixRotationY(renderrotate);

    translation1 = XMMatrixTranslationFromVector(cubeposition);
    cubeworld1 = translation1;

    forwardcube = cube2transform + directioncubeNorm ;
    

    translation2 = XMMatrixTranslation(-5.0f,0.0f,4.5f);

    cubeworld2 = rotation*translation2;

0

Share this post


Link to post
Share on other sites

You have vectors called translation, transform, location and position, all of which sound like pretty much the same thing. Then there are variables that contain "cube1" in the name and variables that contain "cube2" in the name, but then there is "cubeposition", which I don't know which cube it's referring to. This makes your code very hard to follow. If we were dealing with working code, I could try to look at what you are computing and deduce what things mean from there, but with non-working code it's just hopeless.

 

Can you either use better names or provide some comments explaining what you are trying to do?

2

Share this post


Link to post
Share on other sites

ok i hope this explains som things

 

 

 

translationform1 =XMVectorSet (xaxis1, 0.0f, zaxis1,0.0f); //the amount that cube1 has to move increses or decreses when i use the arrow keys;
    cube1transform = XMVectorSet(3.0f, 0.0f, 4.5f, 0.0f);  //is the start postion of the first cub that i can move
    cube2transform = XMVectorSet(-5.0f , 0.0f, 4.5f, 0.0f);// is the start position of the second move and stays put
    
    
    cubetranslation1 = D3DXVECTOR3(xaxis1, 0.0f, zaxis1); //does the same as translationform1;
    cubelocation1 = D3DXVECTOR3(3.0f, 0.0f, 4.5f);//is again the start position of the first cube;
    cube2position = D3DXVECTOR3(-5.0f, 0.0f, 4.5f);// is again the start position of the second cube;
                                                      // i use these to calculate the dot product XMVector3Dot returns a vector and i need a float;
                                                    
    cubeposition = cube1transform + translationform1; // calculates the new position of cube1 when cube 1 is moved

    cubepos1 = cubelocation1 + cubetranslation1;  // does same as cubeposition but whit the D3XVECTOR3

    cubeoldpos = cubepos1 - cubetranslation1; // caluclates the old postion of cube1;

    direction2 = direction2;     // direction2 = (0.0f,0.0f,1.0f)  i also tried here direction2= cubeoldpos -cube2position to calulate the direction that he is now facing;
    direction1 = cubepos1 - cube2position;

    D3DXVec3Normalize(&direction2Norm, &direction2);
    D3DXVec3Normalize(&direction1Norm, &direction1);    // normalize direction1 and direction2
    


    renderrotate = D3DXVec3Dot(&direction1Norm, &direction2Norm);// the dot porduct of direction1 and 2
    dot = renderrotate;
    renderrotate = (acos(renderrotate)); // calculate the acos of dot


    if (dot < 0)
        renderrotate *=-1;

    else
    renderrotate *=1;            //this i us to get the direction to rotate  but dont know if this is corect




    rotation = XMMatrixRotationY(renderrotate);  //rotation to cube 1

    translation1 = XMMatrixTranslationFromVector(cubeposition);  // traslation of the first cube using the xmvextors;
    cubeworld1 = translation1;

    
    

    translation2 = XMMatrixTranslation(-5.0f,0.0f,4.5f);

    cubeworld2 = rotation*translation2;    //the rotation and translation of second cube;

0

Share this post


Link to post
Share on other sites


2.) Why are variable names chosen so that they are not distinguishable from others?
 
3.) Why are variable names for semantically the same thing so different as for cubepos1 and cube2position?

 

My reply isn't a slam on aikender. It's meant to serve as encouraging new developers to 

 

The reason is because new developers don't think good consistent names are important. But truthfully, this is one of my baseline criteria for judging whether or not someone is a good programmer.

 

Again, I'm not ripping on aikender. I was worse back in the olden-days when I was in college (like a million years ago). I used single and dual character variable names all the time starting out. Typing out a long variable name was "a wast of time" because I was smart enough to keep track of everything just fine. But I was an ignorant arrogant student! :) Sure I could keep track of several variables in an insignificant little program. But in the real world, projects can have millions of lines of code. You might not see a bit of code for MONTHS at a time. If your code isn't named correctly, you'll waste hours trying to figure out exactly what's going on.

 

Not to mention, at your first real job you'll probably be fixing other people's crapily written code. And one of the reasons why his code is buggy is because he didn't take a few minutes to think about a proper name! angry.png

 

I think you can see our point aikender, because already, you're having trouble making sense of the code yourself. Games are one of the most complex pieces of software you can write. 

 

Anyway. One thing you could do to debug your problem is loop through the points of a circle, and output the rotation that you calculate and compare it to what you expect to get. Say from -2pi to 2pi, stepping through at pi/6. This should point you to where your calculations are wrong, but haegarr already pointed out the problem in his #5. If you have any more problems getting it right, I recommend doing this as you work the kinks out of your code.

 

- Eck

0

Share this post


Link to post
Share on other sites

Hello. when you get your code fixed up, you will want to look up atan2 function on google.

 

used like this.

 

v3 unitfacingdirection(0,0,1);//facing the z direction this is the meshes exported facing

v3 targetpos;//the object you want to face at position

v3 totargetdirection = targetpos - unitfacingdirection;

 

totargetdirection.normalize();

 

double angle = atan2(totargetdirection.x, totargetdirection.z);//if your terrain is on the x , z plane.

2

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