Rotate in X axis X'
X' = X Y'
Y' = Ycos(theta) - Zsin (theta) Z'
Z' = Ysin(theta) + Zcos(theta)
Rotate in Y axis X'
X' = Zsin(theta) + Xcos(theta) Y'
Y' = Y Z'
Z' = Zcos(theta) - Xsin(theta)
I put them in this for loop in this function below. void DBPB() { DB = 0; DBIZ = 0; //if(XR < 0){XR = 360;} //if(XR > 360){XR = 0;} //if(YR < 0){YR = 360;} //if(YR > 360){YR = 0;} //if(ZR < 0){ ZR = 360;} //if(ZR > 360){ZR = 0;}
void DBPB() { DB = 0; DBIZ = 0; //if(XR < 0){XR = 360;} //if(XR > 360){XR = 0;} //if(YR < 0){YR = 360;} //if(YR > 360){YR = 0;} //if(ZR < 0){ ZR = 360;} //if(ZR > 360){ZR = 0;} //Convert current rotation values into Radian XRa = (RayXr / 180 * PI); YRa = (RayYr / 180 * PI); //ZRa = (ZR / 180 * PI); //The origin is set to zero and the line that is in the correct axis for the camera is added. TDX = 0; TDY = 0; TDZ = RayLength; //Raycast for(RayLength = 0; RayLength > -7; RayLength -= .1) { //Rotate in X axis ROX = TDX; ROY = (TDY*cos(XRa)) - (TDZ*sin(XRa)); ROZ = (TDY*sin(XRa)) + (TDZ*cos(XRa)); //Rotate in Y axis RTX = (ROZ*sin(YRa)) + (ROX*cos(YRa)); RTY = ROY; RTZ = (ROZ*cos(YRa)) - (ROX*sin(YRa)); //Rotate in Z axis(Not used) //X = X*cos(theta) - y*sin(theta) //Y = X*Sin(theta) + y*cos(theta) //Z = Z //std::cout << "Rotated X :" << RTX << " Y:" << RTY << " Z :" << RTZ << std::endl; CPX = static_cast<int>(RTX+PX); CPY = static_cast<int>(RTY+PY); CPZ = static_cast<int>(RTZ+PZ); //When not inside a block in creative //This will hold the position of the block //before the selected block. if(DB == 0 && DBIZ == 0) { PBX = CPX; PBY = CPY; PBZ = CPZ; } if(Blocks[CPX][CPY][CPZ] != 0 && Blocks[CPX][CPY][CPZ] != NULL && DB == 0) { //Toggle bool DB std::cout << "Collided X :" << CPX << " Y:" << CPY << " Z :" << CPZ << std::endl; //Detected Collision at BBX, BBY, BBZ BBX = CPX; BBY = CPY; BBZ = CPZ; RayLength = -7; DB = 1; DBIZ = 1; } } }