# JackBob

Member

23

102 Neutral

• Rank
Member
1. ## Tracking and applying that to rotation to follow what I want tracked

1. it was just there from previous tries and I was going to eventually get it out of there 2. Well its a 3d game. so in order to get the rotation on the x plane I am just using X and Z coordinates. And when I want it to move up and down I'll use Y and X 3. and no, in a quaternion rotation in order to get to turn left or right you have to use the Y component that way it rotates around the Y axis I'm hoping this helps clear things up. Probably not and I don't have anything to open a .tar.gz right now since I'm just quickly on my way and i'm not sure if thats for 2d or 3d. I've been able to do it in a 2d game before like 4 years ago but this time I think its the rotations screwing me up big time Anyhow thanks for the replies does asin return in degrees then?
2. ## Tracking and applying that to rotation to follow what I want tracked

I know this is silly and been asked on here 500 million times. Only I couldn't find any of those times so I figured I would make a topic while thinking on this I got a turret that needs to constantly rotate to a target My tracking and rotation seems to be way off this is what i'm trying so far. I'm actually trying just to get it to track on the x axis right now then when I get it working put it to the Y axis as well [source] distance = sqrt((float)(pow(position.x - target.x, 2)+pow(position.z-target.z, 2))); xChange = asin((position.x - target.x)/distance); yChange = sin(target.y - position.y); D3DXQUATERNION y; if(oldXChange!=xChange) { D3DXQuaternionRotationAxis(&y, &D3DXVECTOR3(0.0f, 1.0f , 0.0f), xChange);//*(D3DX_PI/180)); // main rotation for the gun gunRotation = y * gunRotation; } oldXChange = xChange; [/source] 2 issues i'm having here. Fixing one might fix the other 1. if I move the turret position it actually just spins around and around rather than attempting to track to the target 2. obviously its not tracking. another thing, I shouldn't have to convert from degrees to radians or vice versa right? it should all be in radians correct? Any ideas on what the crap I'm doing wrong? C++ directx9 btw Thanks for anything you might be able to help me with
3. ## Six degrees of freedom help (Quaternions)

Solution! I figured it out about 2 weeks but I am just now posting the solution. It was actually really stupidly easy. the getAX() getAY() and getAZ() are just my ships rotation angles. When I press left on the keyboard my X angle goes down. AX = angle X and the variable turnSpeed which you see in the QuaternionRotationAxis can be anycnumber really. I could put 0.01 in there and it would still rotate. It is just a variable I have in my game which determines how fast I wanna rotate [source] yawChange = getAX()-oldYaw; pitchChange = getAY()-oldPitch; rollChange = getAZ()-oldRoll; D3DXQUATERNION y; D3DXQuaternionRotationAxis(&y, &D3DXVECTOR3(pitchChange, yawChange , rollChange), turnSpeed); currentRot = y*currentRot; D3DXQuaternionNormalize(&currentRot, &currentRot); oldYaw = getAX(); oldPitch = getAY(); oldRoll = getAZ(); [/source] I hope this is clear for anyone who is trying to figure this out as well and if not just Message me!
4. ## Six degrees of freedom help (Quaternions)

Yeah I am =) and of course if once I figure it out I'll post back the solution =) I hoping also someone might give me some insight =)
5. ## Six degrees of freedom help (Quaternions)

Ok I seem to have made some progress here. Now I am just confused on one thing my code [source] D3DXMATRIX angles; D3DXMatrixRotationYawPitchRoll(&angles, 0.0f, 0.0f, 0.0f); // Rotate based off ships rotation D3DXVECTOR3 yaw = D3DXVECTOR3(0.0f, 1.0f, 0.0f); D3DXVECTOR3 pitch = D3DXVECTOR3(1.0f, 0.0f, 0.0f); D3DXVECTOR3 roll = D3DXVECTOR3(0.0f, 0.0f, 1.0f); D3DXVec3TransformCoord(&yaw, &yaw, &angles); D3DXVec3TransformCoord(&pitch, &pitch, &angles); D3DXVec3TransformCoord(&roll, &roll, &angles); D3DXQUATERNION y; D3DXQUATERNION p; D3DXQUATERNION r; D3DXQuaternionRotationAxis(&y, &yaw, yawChange); D3DXQuaternionRotationAxis(&p, &pitch, pitchChange); D3DXQuaternionRotationAxis(&r, &roll, rollChange); currentRot = y*r*p; D3DXQuaternionNormalize(&currentRot , &currentRot); D3DXMATRIX rots; D3DXMatrixRotationQuaternion(&rots, &currentRot); g_pd3dDevice->SetTransform(D3DTS_WORLD, &(angles*rots*matTranslate)); [/source] My problem is in the yawpitchroll matrix i'm not sure what the hell do put there. I know that will be the angle it all rotates around but how do I get that angle while also changing the angle of my ship? It seems to be when I do both at the same time they negate eachother and still rotate off of a 0.0f 0.0f 0.0f axis. Well lemm rephrase that. The yaw works but roll and pitch don't. And yes I do know right now yawpitchroll is set to 0.0f 0.0f 0.0f right now. Because I'm not sure how to find the axis while changing axis if that makes any sense
6. ## Six degrees of freedom help (Quaternions)

Ok, like the topic says. I am looking for space type of movement for a mesh (6dof). I know quaternions is how to do this from all the research I've done. And speaking of all the research I've done I haven't been able to figure it out by literally 30hours of google. Which makes me feel absolutely dumb. I haven't been able to find a good tutorial or anything really with actual code. So I figured I'd post here and see what happens. My attempts have failed but I will post what I got to see how close/far off I am directx9 c++ [source] D3DXMatrixRotationYawPitchRoll(&pitch, two.getAX(), two.getAY(), two.getAZ()); // Rotate based off ships rotation D3DXVECTOR3 axis = D3DXVECTOR3(0.0f, 0.0f, 0.0f); D3DXVec3TransformCoord(&axis, &axis, &pitch); yawChange = two.getAX()- oldYaw; // two.getAX() is the yaw angle of the ship. pitchChange = two.getAY() - oldPitch; rollChange = two.getAZ() - oldRoll; oldYaw = two.getAX(); oldPitch = two.getAY(); oldRoll = two.getAZ(); D3DXQUATERNION rot; D3DXQUATERNION rotChange = D3DXQUATERNION(yawChange, pitchChange, rollChange, 0.0f); //D3DXQuaternionRotationAxis(&newRotation, &axis, two.getAX()); //D3DXQuaternionMultiply(&currentRot, &currentRot, &rotChange); rot = rotChange * currentRot; //D3DXQuaternionNormalize(&currentRot , &currentRot); D3DXMATRIX rots; D3DXMatrixRotationQuaternion(&rots, &rot); //currentRot = newRotation; [/source] Right now I have 2 attempts kind of thrown together to make one giant mess of ugly. I know all the float values(yawChange oldYaw) just have to be the most absolutely wrong way to do it. As of right now. either attempt just makes my ship not rotate at all. and when I uncomment the normalize my ship just automagically disappears. Which I can't figure out why. I've read alot of this "1. get your ship a nice little variable of quaternion type and name it something ugly like currentRotation. 2. get 3 variables like yawChange, pitchChange, rollChange. each frame get user input there 3. build quaternion rotationChange from these. 4. set currentRotation = rotationChange * currentRotation 5. crate matrix from currentRotation. 6. normalize currentRotation from time to time. " alot of places seem to say something similar to this. But it makes no sense to me since you aren't rotating anything. Atleast it seems that way to me. Any links or insight would be much appreciated (and the tutorial at code guru just makes no sense at all p.s) You guys/gals are wonderful on this forum btw. Just thought I'd point that out. I have already gotten alot of help on here from some good people.
7. ## Destructor crashing game?

Ok I've finally got around to trying to implement OnLostDevice and OnResetDevice and for some odd reason they are still leaking memory. And when I comment them out the memory errors are on so l must be doing something wrong. i have a bool checkDevice() that i use when I do if(checkDevice()) render(); so that way if something is wrong it wont try and render. I'm hoping I did that correctly and in this checkDevice its [source] bool checkDevice() { switch(g_pd3dDevice->TestCooperativeLevel()) { case D3DERR_DEVICELOST: { onLostDevice(); return false; } case D3DERR_DEVICENOTRESET: { onResetDevice(); return false; } } return true; }[/source] now I know the device reset needs some work and that was the next thing to do but for the moment onLostDevice seems to not work onLostDevice just has dxfont->OnLostDevice(); and so on. I tried just calling this method right as the loop is ending before I call my release method for everything and I'm still getting memory leaks. Any idea what I could be doing wrong? Thanks for all the help sprite->onLostDevice();
8. ## Destructor crashing game?

The program would still run correctly until shutdown time if it is being released after IDirect3DDevice9 wouldn't it? since my problem seems to be immediate on start up. I got the vector compiling finally kinda std::vector<LPDIRECT3DTEXTURE> ttexture; // constructor method LPDIRECT3DTEXTURE temp = NULL; for loopy createtexture(blahbluhblah... &temp); ttexture.push_back(temp) and it all works just fine and my texture memory leaks are now gone! YaY! Thanks mhagain Although I'm still curious as to why my destructor hates me also p.s. could anyone tell my whyD3DXCreateFont creates a memory leak?
9. ## Destructor crashing game?

When I said global variables I meant as they are global inside the Ship class. So when I create a new object for the class each object should have its own variables right? I'm thinking though, when I create the object in my main class i'm doing Ship one = Ship(insertstuff here); and thats it. I notice some people have pointers to there objects or something of the sort. I may have that all wrong. now that I think about it the second ship seems textures itself red for no real reason. And I know the Bi plane has red on it. and as for my attempt I did std::vector<D3DMATERIAL9*> mmaterial; then tried to define it doing mmaterial = new D3DMATERIAL9(NumMaterials); also mmaterial = new D3DMATERIAL9[NumMaterials]; also mmaterial = new <D3DMATERIAL9> and thats about as far as I got on that one. I notice in all the examples they do std::vector<D3DMATERIAL9*> mmaterial(NumMaterials); I'm not sure how to break that up at all though I know its got to be absolutely simple. But for the life of me I can't figure it out thanks for your help rip-off
10. ## Destructor crashing game?

After putting in place the proper checks and what not into the constructor and destructor as soon as I run it it acts like its on a never ending loop that cause both the program and visual studio to freeze up. This has only ever happened to me when a memory leak has happened that I just completely missed. But this time I can't see anything I'm missing. If its a destructor why at run time would it cause this? My class does not obey the rule of three. After reading up on that I couldn't imagine that being the cause of this problem. Thanks for the replies by the way guys this problem is frustrating. p.s. I tried the std:vector I was able to declare the variables. But for somereason I couldn't figure out how to set the variables. i.e. mmaterial = ? I tried looking it up online but so far nothing that even remotely shows it. Maybe my searching skills need improving.

12. ## Destructor crashing game?

so in a class I have D3DMATERIAL9* mmaterial; LPDIRECT3DTEXTURE9* ttexture; as global variables that are used for loading in meshs and what not. Whenever I close the program I get memory leaks from them as they are not being destroyed. So simple enough I just make a destructor and in it I put delete[] mmaterial; delete[] ttexture; inside of it When I start up my game it crashes the game and visual studio. And I'm not particularly sure why... my destructor looks like this Ship::~Ship() { delete[] mmaterial; delete[] ttexture; } Any insight or links to other articles would be helpful =) or atleast what to search for since it seems apparently I can't find anything Thanks
13. ## Rotating camera around the y axis with a locked camera on a mesh

Thanks iedoc that has been a big help =) and works =) except for one tiny thing. when ever I move the object now once I rotate that camera just goes absolutely nuts and goes which ever way it wants to. would re arranging the order or the entire thing fix that? or do you have any ideas? and I really need to change the name of the work vector. It was a desperation name haha Either way thanks =)
14. ## Rotating camera around the y axis with a locked camera on a mesh

Ok i've figured it out! I needed to do this D3DXMATRIX pitch; D3DXMatrixRotationYawPitchRoll(&pitch, two.getAX(), two.getAY(), two.getAZ()); [color="#008000"][color="#008000"]// Rotate based off ships rotation D3DXVECTOR3 work = D3DXVECTOR3(0.0f, 5.0f, 20.0f); [color="#008000"][color="#008000"]// set how far up we want the camera and back D3DXVec3TransformCoord(&work, &work, &pitch); [color="#008000"][color="#008000"]// transform the rotation matrix and the up and back vector into the vector work+=two.Position(); and now it works perfectly. But going back to the problem you guys started mentioning in the beginning. The upVector. It seems to not be cooperating with me at all and I'd like to slap it. the vector is (0.0f, cos(two.getAY()), 0.0f) and at 90 degrees it flips the camera which is 90 degrees to soon. So I simply divided the angle by two cos(two.getAY()/2) and for some strange reason it still flips at 90 degrees... Any ideas why?
15. ## Rotating camera around the y axis with a locked camera on a mesh

I've tried doing what you said with no luck really. This is frustrating really. could you show me how to implement the D3DXMatrixRotationYawPitchRoll() and D3DXVec3TransformCoord() this is what I tried D3DXMatrixRotationYawPitchRoll(&look, two.getAX(), two.getAY(), two.getAZ()); look *= 20.0f; D3DXVECTOR3 work = look; work+=two.Position(); this just pretty much sets it to the left of the object and when I yaw it looks at the left of it and the camera follows it but when I pitch the camera just doesn't even move. and the *20 is for the distance I was hoping to keep it away from the camera. I have had no luck. Thanks iedoc