Jump to content
  • Advertisement

HobbyDude

Member
  • Content Count

    16
  • Joined

  • Last visited

Community Reputation

100 Neutral

About HobbyDude

  • Rank
    Member
  1. HobbyDude

    Point a model in direction vec(x, y, z)

    LOL, posted on the wrong forum... This is for a GameMaker game. I'll post on the GameMaker forum now (blush)...
  2. Hello! How do I point a model in the direction vec(x, y, z)? I have a normalized 3D vector x, y, z and I want to point a model to face the direction the vector is pointing. How do I do that? I've played around with 'd3d_transform_set_rotation_axis()' and 'd3d_transform_set_translation()' but have had no luck. Thanks in advance for the help!
  3. HobbyDude

    6DOF help

    I figured it out... I rotated the entire scene along the display's 'y' axis and successfully scooted the 'left' and 'forward' axes into their proper location. Before, I was trying to rotate the scene using the ship's 'y' axis and that's why I couldn't get it working... Oops!
  4. HobbyDude

    6DOF help

    Thanks for the reply, ApochPiQ. I already tried that: [font="Courier New"]d3d_set_projection(0, 0, 0, ma11-ma21, ma12-ma22, ma13-ma23, ma31, ma32, ma33);[/font] and I get the same result. What it looks like is when I move left/right, the screen wipes left/right the way I expect. But when I move up/down or roll, the axis of rotation appears to be the left or right edge of the screen. It looks as if the entire axis of rotation is spun 90 degrees out of whack (y-axis rotation is from the left edge, and x-axis is from the right edge of screen). I can't figure out how to get the 'y' axis to be in front of the player, and the 'x' axis to be to the right (or left) of the player.
  5. HobbyDude

    6DOF help

    I think I almost got it, but I'm having trouble getting it tweaked to work... This is a GameMaker game, and I'm playing around with the 3D features of the registered version of the programming environment. I'm trying to make a 6dof camera, and I have it working when rotated along the 'z' axis, but that's mainly because of how the camera works in GameMaker. Here's the camera prototype in GameMaker: [font="Courier New"]d3d_set_projection(xfrom,yfrom,zfrom,xto,yto,zto,xup,yup,zup)[/font][font="Arial"] [/font] The camera is pretty much just a vector created from the points 'from' and 'to', and uses the 'up' vector to orient itself. I created a rotation matrix called 'ma', and it's incremented and then orthoganilized. The code works in a different game I worked on recently, but I can't get it to work with this camera. 'ma' is a row matrix. When I do this: [font="Courier New"]d3d_set_projection(ma11, ma12, ma13, ma21, ma22, ma23, ma31, ma32, ma33);[/font] it works when rotating along the 'z' axis, since the camera's 'up' vector is a vector. I can't figure out how to get it to work with the 'x' and 'y' axes, since the camera uses two points to create a vector instead of using two vectors for the 'x' and 'y' axes (similar to the 'z', or the 'up', axis). Would you help me get this to work? Thanks in advance for the help!
  6. HobbyDude

    3D rotation question

    You guys rock, that's all there is to it. Sorry I didn't reply earlier, lots of stuff going on (work, life, kid, wife, dog, etc). But thanks to your help, I got the rotations I was looking for! Now I can finish work on my magnum opus super cool completely and totally original 'Wing Commander' clone photo-realistic asteroids game... NOT! LOL! Actually, it's pretty simplistic and goofy game, but it's a fun project for me and my 4-yr old son loves playing it. Thanks again for the help, I REALLY appreciate it!
  7. HobbyDude

    Update up, forward, right vectors.

    I heard from some of the other math experts (I'm definitely not one of them, lol!) that floating-point imprecision can cause that to happen. The trick is to re-orthogonalize the rotation matrix. I'm using a different sized matrix (3x3 matrix), but you should be able to modify the below code and get it to work in your project: // Orthogonalize the orientation matrix! var rfx, rfy, rfz, rfMag; var rux, ruy, ruz, ruMag; var rx, ry, rz, rMag; // Cross-product of right/forward vectors (store in 'up')... rfx = matrix[5]*matrix[6] - matrix[8]*matrix[3]; rfy = matrix[8]*matrix[0] - matrix[2]*matrix[6]; rfz = matrix[2]*matrix[3] - matrix[5]*matrix[0]; rfMag = sqrt(rfx*rfx + rfy*rfy + rfz*rfz); rfx = rfx/rfMag; rfy = rfy/rfMag; rfz = rfz/rfMag; // Cross-product of right/up vectors (store in 'forward')... rux = rfz*matrix[3] - rfy*matrix[6]; ruy = rfx*matrix[6] - rfz*matrix[0]; ruz = rfy*matrix[0] - rfx*matrix[3]; ruMag = sqrt(rux*rux + ruy*ruy + ruz*ruz); rux = rux/ruMag; ruy = ruy/ruMag; ruz = ruz/ruMag; // Normalize 'x' vector... rMag = sqrt(matrix[0]*matrix[0] + matrix[3]*matrix[3] + matrix[6]*matrix[6]); rx = matrix[0]/rMag; ry = matrix[3]/rMag; rz = matrix[6]/rMag; // All's orthaganlized! Store new values into // ship's 'ma' matrix... matrix[0] = rx; matrix[1] = rfx; matrix[2] = rux; matrix[3] = ry; matrix[4] = rfy; matrix[5] = ruy; matrix[6] = rz; matrix[7] = rfz; matrix[8] = ruz; If you plug in this code and notice nothing except your speed errors are gone, then it worked! If the visuals go all over the place, I probably got a couple of matrix elements inverted or something like that and some simple tweaking should get it to work (I translated from my own variables to something more understandable before posting the code). Anyway, I was told that this code doesn't have to be executed on every frame, so you can make a call to this code every now and then (every ten frames?) or perform some low-cost calculations to see if an axis has gone out of tolerance. Hope that helps! I'm still pretty new to this, so please let me know if it works! EDIT: I plugged in this code after I updated the old orientation matrix with the new values, just before I put things on the screen.
  8. HobbyDude

    Update up, forward, right vectors.

    Nevermind about posting your code, I just got it to work. Thanks for the explanation, it really helped out! It's pretty cool how things go together when one thing is changed, heh! I had a few numbers completely wrong (treated a column matrix like a row matrix - ooooops!) but once I played around with it, it all worked out. Thanks for sharing your success!
  9. HobbyDude

    Update up, forward, right vectors.

    Coolness, I'm glad you got it to work! I have a tremendous favor to ask you... Could you post the code that made it work? I'm stuck on the same thing for my own game and I can't figure out how to get the rotations to work correctly. Right now I'm getting your 'very strange rotations' (I've been stuck on that for a week), and I'm doing the yaw/pitch/roll arbitrary axis matrices while multiplying all the matrices together. Thanks for the info!
  10. HobbyDude

    3D rotation question

    Thanks for the replies, I really appreciate it! I definitely know more about matrix and vector math than I did before starting this project, lol! I've been implementing your ideas and have some weirdness happening... - When pressing a direction key, the view goes all over the place. The viewport doesn't go ballistic, the view just sways and swirls around as if I was getting sucked into a black hole. - When I do the cross-product calculations, the view flip-flops between a positive and negative 'forward' vector. In other words, I can see me going forward and backwards at the same time. I can't seem to identify where I'm messing up... Am I doing these calculations correctly? Arbitrary rotation calculations: // My game's ship (viewport) orientation matrix: // ma11 ma12 ma13 // ma21 ma22 ma23 // ma31 ma32 ma33 // Arbitrary rotation around 'x' axis... vX = ma11; vY = ma21; vZ = ma31; x11 = ((1-cos(cAnglX))*vX*vX + cos(cAnglX)); x12 = ((1-cos(cAnglX))*vX*vY - sin(cAnglX)*vZ); x13 = ((1-cos(cAnglX))*vX*vZ + sin(cAnglX)*vY); x21 = ((1-cos(cAnglX))*vX*vY + sin(cAnglX)*vZ); x22 = ((1-cos(cAnglX))*vY*vY + cos(cAnglX)); x23 = ((1-cos(cAnglX))*vY*vZ - sin(cAnglX)*vX); x31 = ((1-cos(cAnglX))*vX*vZ - sin(cAnglX)*vY); x32 = ((1-cos(cAnglX))*vY*vZ + sin(cAnglX)*vX); x33 = ((1-cos(cAnglX))*vZ*vZ + cos(cAnglX)); After calculating arbitrary axis rotations for yaw/pitch/roll, multiply them together and then multiply new matrix to original one... // Multiply 'x' and 'y' matrices... n11 = x11*y11+x12*y21+x13*y31; n12 = x11*y12+x12*y22+x13*y32; n13 = x11*y13+x12*y23+x13*y33; n21 = x21*y11+x22*y21+x23*y31; n22 = x21*y12+x22*y22+x23*y32; n23 = x21*y13+x22*y23+x23*y33; n31 = x31*y11+x32*y21+x33*y31; n32 = x31*y12+x32*y22+x33*y32; n33 = x31*y13+x32*y23+x33*y33; // Multiply above with 'z' matrix... t11 = n11*z11+n12*z21+n13*z31; t12 = n11*z12+n12*z22+n13*z32; t13 = n11*z13+n12*z23+n13*z33; t21 = n21*z11+n22*z21+n23*z31; t22 = n21*z12+n22*z22+n23*z32; t23 = n21*z13+n22*z23+n23*z33; t31 = n31*z11+n32*z21+n33*z31; t32 = n31*z12+n32*z22+n33*z32; t33 = n31*z13+n32*z23+n33*z33; // Multiply old 'ma' matrix with new 'm' matrix... m11 = ma11*t11+ma12*t21+ma13*t31; m12 = ma11*t12+ma12*t22+ma13*t32; m13 = ma11*t13+ma12*t23+ma13*t33; m21 = ma21*t11+ma22*t21+ma23*t31; m22 = ma21*t12+ma22*t22+ma23*t32; m23 = ma21*t13+ma22*t23+ma23*t33; m31 = ma31*t11+ma32*t21+ma33*t31; m32 = ma31*t12+ma32*t22+ma33*t32; m33 = ma31*t13+ma32*t23+ma33*t33; Cross-product and normalization calculations. 'm' is the new rotation matrix, and 'ma' is the original matrix... // Cross-product of right/forward vectors (store in 'up')... ma12 = m21*m33 - m31*m23; ma22 = m31*m13 - m11*m33; ma32 = m11*m23 - m21*m13; rfMag = sqrt(ma12*ma12 + ma22*ma22 + ma32*ma32); ma12 = ma12/rfMag; ma22 = ma22/rfMag; ma32 = ma32/rfMag; // Cross-product of right/up vectors (store in 'forward')... ma13 = m21*ma32 - m31*ma22; ma23 = m31*ma12 - m11*ma32; ma33 = m11*ma22 - m21*ma12; ruMag = sqrt(ma13*ma13 + ma23*ma23 + ma33*ma33); ma13 = ma13/ruMag; ma23 = ma23/ruMag; ma33 = ma33/ruMag; // Normalize 'x' vector... rMag = sqrt(m11*m11 + m21*m21 + m31*m31); ma11 = m11/rMag; ma21 = m21/rMag; ma31 = m31/rMag; The order of what I'm doing is as follows... - Calculate new yaw/pitch/roll matrices using arbitrary axis calculations. - Multiply yaw and pitch matrices into a temp matrix, and the temp and roll matrices into a new matrix. - Multiply the old matrix and new matrix together. - Orthogonalize the new matrix. Let me know if you need to see more code, or any more info. I bet it's something painfully obvious, but I've stared at the code for so long that I need a fresh set of eyes to help me sort this out. Thanks for putting up with me, I hope you're not getting sick of my posting. I definitely appreciate all the help you're giving me!
  11. HobbyDude

    3D rotation question

    That's weird, I thought I was performing the cross-product on the new vector... ma®© is supposed to be the original axis vector, and m®© is supposed to be the updated vector. What I thought I was doing was to perform an arbitrary rotation around the ship's 'pitch' and 'yaw' axes into the matrices 'x' and 'y', then multiply both results into the third matrix 'm'. Next, I performed cross-product calculations and normalized them, and plugged the new values back into the matrix 'ma'. Finally, I used the values in 'ma' to move the game sprites into the 3D space. I changed the last part of my code to read like this: // Apply Pitch/yaw (xTemp/yTemp/zTemp is an object's x/y/z location in the game world)... tX = xTemp; tY = yTemp; tZ = zTemp; xTemp = tX*ma11 + tY*ma12 + tZ*ma13; yTemp = tX*ma21 + tY*ma22 + tZ*ma23; zTemp = tX*ma31 + tY*ma32 + tZ*ma33; I still get the same result - I push a direction control (left/right, up/down), and the ship's view moves as far as direction*frameTime and stops, and then returns to the original position when the direction control is released. It's as if the 'ma' matrix isn't getting updated with the new position information... I'm sure the problem is as plain as the nose on my face, but I'm still having a hard time grasping this matrix stuff (I'm used to writing 2D games and simple 2D rotations). Can you show me where I'm getting mixed up?
  12. HobbyDude

    3D rotation question

    I'm baaack... I'm still trying to get this working, I read up on some matrix math and played around with some of the basics. Now I'm trying to apply BuffaloJ's idea (looks like forsandifs uses the same method) and can't get it to update my ship's axis vector... If I push the 'up' key, the ship rotates up slightly and then jumps back to its original orientation when I let go of the 'up' key. Same thing if I push 'down', 'left', and 'right', the ship's view moves slightly in that direction and then jumps back to original orientation when I let go of that key. Can you look at this and see what I'm doing incorrectly? Feel free to educate me if you find something I did heinously incorrect, I'm open to learning! // BuffaloJ: // What you want is to keep a matrix to represent // the orientation. Then, to pitch up/down grab the // right vector from the matrix(the first column) // and perform arbitrary axis rotation on the matrix // around the right vector. My matrix is maRC (maRowCol) // Pitch (1st column of ship axis matrix)... vX = ma11; vY = ma21; vZ = ma31; y11 = ((1-cos(cAnglX))*vX*vX + cos(cAnglX)); y12 = ((1-cos(cAnglX))*vX*vY - sin(cAnglX)*vZ); y13 = ((1-cos(cAnglX))*vX*vZ + sin(cAnglX)*vY); y21 = ((1-cos(cAnglX))*vX*vY + sin(cAnglX)*vZ); y22 = ((1-cos(cAnglX))*vY*vY + cos(cAnglX)); y23 = ((1-cos(cAnglX))*vY*vZ - sin(cAnglX)*vX); y31 = ((1-cos(cAnglX))*vX*vZ - sin(cAnglX)*vY); y32 = ((1-cos(cAnglX))*vY*vZ + sin(cAnglX)*vX); y33 = ((1-cos(cAnglX))*vZ*vZ + cos(cAnglX)); // For yaw, use the up from the matrix(the 2nd column) // and use the matrix Z axis for the roll. Euler // angles will not get you the desired motion... // Yaw (2nd column of ship axis matrix)... vX = ma12; vY = ma22; vZ = ma32; x11 = ((1-cos(cAnglY))*vX*vX + cos(cAnglY)); x12 = ((1-cos(cAnglY))*vX*vY - sin(cAnglY)*vZ); x13 = ((1-cos(cAnglY))*vX*vZ + sin(cAnglY)*vY); x21 = ((1-cos(cAnglY))*vX*vY + sin(cAnglY)*vZ); x22 = ((1-cos(cAnglY))*vY*vY + cos(cAnglY)); x23 = ((1-cos(cAnglY))*vY*vZ - sin(cAnglY)*vX); x31 = ((1-cos(cAnglY))*vX*vZ - sin(cAnglY)*vY); x32 = ((1-cos(cAnglY))*vY*vZ + sin(cAnglY)*vX); x33 = ((1-cos(cAnglY))*vZ*vZ + cos(cAnglY)); m11 = x11*y11+x12*y21+x13*y31; m12 = x11*y12+x12*y22+x13*y32; m13 = x11*y13+x12*y23+x13*y33; m21 = x21*y11+x22*y21+x23*y31; m22 = x21*y12+x22*y22+x23*y32; m23 = x21*y13+x22*y23+x23*y33; m31 = x31*y11+x32*y21+x33*y31; m32 = x31*y12+x32*y22+x33*y32; m33 = x31*y13+x32*y23+x33*y33; // Rotation has been applied to last axis matrix, zero this out for the next frame. // We'll update the ship's rotation axis further down. cAnglX = 0.0; cAnglY = 0.0; // You would also need to re-orthaganlize the matrix every // frame or every few frames so accumulated error doesn't // make you scene/model blow up. Do this by grabbing the // right and forward vectors, take the cross product and // store result in the up vector column in the matrix. The // take the side and up vectors and cross and store for the // forward. Make sure the vectors are normalized as well... // X = V x W = (X1, X2, X3) = (V2W3 - V3W2, V3W1 - V1W3, V1W2 - V2W1) // X = R x F = (X1, X2, X3) = (R2F3 - R3F2, R3F1 - R1F3, R1F2 - R2F1) // Right = mx1 // Forward = mx3 var rfx, rfy, rfz, rfMag; var rux, ruy, ruz, ruMag; var rx, ry, rz, rMag; // Cross-product of right/forward vectors (store in 'up')... rfx = m21*m33 - m31*m23; rfy = m31*m13 - m11*m33; rfz = m11*m23 - m21*m13; rfMag = sqrt(rfx*rfx + rfy*rfy + rfz*rfz); rfx = rfx/rfMag; rfy = rfy/rfMag; rfz = rfz/rfMag; // Cross-product of right/up vectors (store in 'forward')... rux = m21*m32 - m31*m22; ruy = m31*m12 - m11*m32; ruz = m11*m22 - m21*m12; ruMag = sqrt(rux*rux + ruy*ruy + ruz*ruz); rux = rux/ruMag; ruy = ruy/ruMag; ruz = ruz/ruMag; // Normalize 'x' vector... rMag = sqrt(m11*m11 + m21*m21 + m31*m31); rx = m11/rMag; ry = m21/rMag; rz = m31/rMag; // Store it all (update ship axis orientation for next frame)... ma11 = rx; ma12 = rfx; ma13 = rux; ma21 = ry; ma22 = rfy; ma23 = ruy; ma31 = rz; ma32 = rfz; ma33 = ruz; ... // Apply Pitch/yaw (xTemp/yTemp/zTemp is an object's x/y/z location in the game world)... tX = xTemp; tY = yTemp; tZ = zTemp; xTemp = tX*m11 + tY*m12 + tZ*m13; yTemp = tX*m21 + tY*m22 + tZ*m23; zTemp = tX*m31 + tY*m32 + tZ*m33; Sorry it's all laid out in a very inefficient manner, I'm keeping this as readable as possible so I can fully understand how it works. Thanks in advance for the help. I'm REALLY excited about getting this to work (and actually understanding WHY it works too)!
  13. HobbyDude

    3D rotation question

    Thanks for the info jyk, I'll check that out. It looks like a very informative book! I also found an article at 'cprogramming.com' that lines out matrix math and quaternions pretty well. I know enough vector math to be dangerous, but I know hardly anything at all about matrix math. I'll go check out those sources and come back if I still can't figure it out. Thanks for the info, and thanks for your patience!
  14. HobbyDude

    3D rotation question

    I'm not sure where to start, jyk. I read BuffaloJ's response (thanks BuffaloJ!), but I don't really understand the math (or terminology - re-orthaganlize?) behind it. Maybe I shouldn't get in this deep this quick... I guess what I don't understand is how to rotate around an arbitrary axis... I know I need an axis of rotation, and I can get that in the form of a vector (it would be the direction the player is facing). I just don' t know how to utilize the axis of rotation. You can see that my code is pretty basic in that it can rotate around the 'x' or 'y' axis and that's about it, and there's no way that I've found to code an arbitrary axis of rotation into it. I hope you can figure out from my post the point where I need help, because I don't really know where to start. Thanks!
  15. HobbyDude

    3D rotation question

    Dang, I just can't wrap my head around this stuff... I'm medicated for adhd so I have a hard time inferring what's being described when all of the steps aren't there. All of the search results for '6dof' I've found use some form of library function rather than stepping out the math involved in the calculations I'm trying to perform. Can any of you direct me to where I can find a step-by-step tutorial on this? I hope I don't sound harsh or anything as that's not my intention, I carry a lot of respect for you! It's just that I have the grammar etiquette of a musk ox. Thanks!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!