I am making a simple 3D game with plane in space. With c++ (win32). But the plane rotation is not realistic. The code I am using for the rotation is the following:
point3D AxisRotation(point3D point,point3D Rotation){
float sx = Sin(Rotation.x*PI/180);
float cx = Cos(Rotation.x*PI/180);
float sy = Sin(Rotation.y*PI/180);
float cy = Cos(Rotation.y*PI/180);
float sz = Sin(Rotation.z*PI/180);
float cz = Cos(Rotation.z*PI/180);
float xy,xz, yx,yz, zx,zy;
xy = cx*point.y - sx*point.z;
xz = sx*point.y + cx*point.z;
yz = cy*xz - sy*point.x;
yx = sy*xz + cy*point.x;
zx = cz*yx - sz*xy;
zy = sz*yx + cz*xy;
point.x = zx;
point.y = zy;
point.z = yz;
return point;}
The axis of the rotation needs to be (Roll,Yaw,Pitch). Does anyone know the code or the math for it ? Thank you. Dave
Try this: (You'll need to call this three times, once for Roll, Yaw, and Pitch). This should work, I've used it in my own game, and it has been unit-tested. Of course, if your vector/point class has its overloaded operators defined differently then it may not give similar results. Here is my vector implementation (as of a few months ago).
point3D RotatePointAroundAxis( const point3D& axis, const float
radians, const point3D& point )
{
float matrix[3][3];
float sn = sinf(radians);
float cs = cosf(radians);
float xSin = axis.x * sn;
float ySin = axis.y * sn;
float zSin = axis.z * sn;
float oneMinusCS = 1.0f - cs;
float xym = axis.x * axis.y * oneMinusCS;
float xzm = axis.x * axis.z * oneMinusCS;
float yzm = axis.y * axis.z * oneMinusCS;
matrix[0][0] = (axis.x * axis.x) * oneMinusCS + cs;
matrix[0][1] = xym + zSin;
matrix[0][2] = xzm - ySin;
matrix[1][0] = xym - zSin;
matrix[1][1] = (axis.y * axis.y) * oneMinusCS + cs;
matrix[1][2] = yzm + xSin;
matrix[2][0] = xzm + ySin;
matrix[2][1] = yzm - xSin;
matrix[2][2] = (axis.z * axis.z) * oneMinusCS + cs;
return point3D
(
matrix[0][0] * point.x + matrix[0][1] * point.y + matrix[0][2] * point.z,
matrix[1][0] * point.x + matrix[1][1] * point.y + matrix[1][2] * point.z,
matrix[2][0] * point.x + matrix[2][1] * point.y + matrix[2][2] * point.z
);
}
If you're trying to rotate an entire plane then I suspect you have a rotation matrix, if you're using DirectX you could use something like D3DXMatrixRotationRollYawPitch(&mRotation, rotation.y, rotation.x, rotation.z);
I'm not sure if that's the exact function name.
from my camera class: void Camera::RotateCamera(float h, float v){ hRadians += h; vRadians += v; cam_target.y = cam_position.y+(float)(radius*sin(vRadians)); cam_target.x = cam_position.x+(float)(radius*cos(vRadians)*cos(hRadians)); cam_target.z = cam_position.z+(float)(radius*cos(vRadians)*sin(hRadians)); cam_up.x = cam_position.x-cam_target.x; cam_up.y = ABS(cam_position.y+(float)(radius*sin...I am having trouble with a camera class I am trying to use in my program. When I change the camera_target of the gluLookAt call, my whole terrain is rotating instead of just the camera rotating like
( 10.0f, 0.0f, 0.0f, 1.0f ); // z rotation Are my maths and approach correct, or am I completely wrong? Finally, I'm using the glm library with OpenGL / C++ for this. Is the order of x rotation...I'm attempting to create a 3d tree procedurally. I'm hoping that someone can check my vector rotation maths, as I'm a bit confused. I'm using an l-system (a recursive algorithm for generating... by +10 degrees in the X axis and a similar amount in the Z axis, relative to the trunk. I know that I should keep a rotation matrix at each branch, so that it can be applied to child branches, along
x, int y) { if (key=='w') { float xrotrad, yrotrad; yrotrad = (yrot / 180 * 3.141592654f); xrotrad = (xrot / 180 * 3.141592654f); xpos += float(sin(yrotrad))*5; zpos -= float(cos...(sin(yrotrad))*5; zpos += float(cos(yrotrad))*5; ypos += float(sin(xrotrad))*5; } if (key=='d') { float yrotrad; yrotrad = (yrot / 180 * 3.141592654f); xpos += float(cos(yrotrad))*5; zpos += float(sin(yrotrad))*5; } if (key=='a') { float yrotrad; yrotrad = (yrot / 180 * 3.141592654f); xpos -= float(cos(yrotrad))*5; zpos -= float(sin(yrotrad))*5; } if (key
code shows the changes I made to get accurate physics. void GameState::createScene() { m_pSceneMgr->createLight("Light")->setPosition(75,75,75); // Physics // As a test we want a floor plane...::createScene() { m_pSceneMgr->createLight("Light")->setPosition(75,75,75); // Physics // As a test we want a floor plane for things to collide with Ogre::Entity *ent; Ogre::Plane p; p.normal = Ogre...::toString(m_pNumEntities), "cube.mesh"); entity->setCastShadows(true); Ogre::AxisAlignedBox boundingB = entity->getBoundingBox(); // The ogre bounding box is slightly bigger so I am reducing
a = 0; a < (int)groups.size(); a++) { if(groups[a].type == "prop") { //Code for rotation glPopMatrix(); glPushMatrix(); float x,y,z; x = y = z = 0; int...Im writing a game for which, one of the models are loaded from an .obj file. It's a model of a plane, and I want to rotate the propeller. The object file is broken into groups, and the propeller is identified, so that's all good. I'm writing the game in C++ with OpenGl/GLFW The drawing function is: int win_width; int win_height; glfwGetWindowSize(&win_width, &win_height); float win
an elliptical path around the teapot, multiplying either cos() or sin() (not both) by 2. This works as well but does not have the same effect I was expecting. The view rotates around the teapot, but I...I am fairly new to openGL( 3 months ) and am asking for assistance in understanding the fundamentals behind gluLookAt(). Currently I have spent most of my time with openGL modeling scenes... the standard glutSolidTeapot(0.5). Then in an attempt to create a "camera" revolve around the teapot, in an idle callback function I write this glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( cos
between frame updates or other problems..... Finally I would like to know how my organization, planning, etc is.. Thanks! my UPDATED, WORKING Code: #include<SFML/Graphics.hpp> #include<SFML/System.hpp> #include<cmath> #include<vector> # define M_PI 3.14159265358979323846 sf::RenderWindow Window; template<typename T> void CalculateMove(T Time, T Speed, T... to be switched buffY= sin(Angle / 180 * M_PI)/ (1.f/(Speed*Time)); buffX= sin((180-Angle-90)/ 180 * M_PI)/ (1.f/(Speed*Time));} else{// Movement is a straight line on X or Y
, matProjection, matFinal; // increase the time varaible and send to the effect static float Time = 0.0f; Time += 0.001f; // create a rotation matrix D3DXMatrixRotationY(&matRotate...(); }; #endif If I call Init() from game.cpp, the code works fine, if I call cube->init(), just as this function is entered (not when the other one is left), the device pointer suddenly has an address...Basically when placed in the same file this works fine, but if placed in separate files (and I have tested this) just after Init() is called, the pointer to ID3D10* device's value is suddenly
); When using this code I'm able to detect a ray intersection via a sphere, but I have questions when determining an intersection via a plane. First off should I be using my vRayOrig & vRayDir variables for the plane intersection tests or should I be using the new vectors that are created for use in object space? When looking at a site like this for example: http://www.tar.hu...I'm developing a picking system that will use rays that intersect volumes and I'm having trouble with ray intersection versus a plane. I was able to figure out spheres fairly easily, but planes