- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在不使用 glRotatef
的情况下在 JOGL 中绕 Z 轴旋转图像功能?我不明白如何获得 z' 因为没有 e.getZ()
功能。如何计算 z_prime
?现在,当我尝试绕 z 轴旋转时,它就像一开始就绕 z 轴旋转,然后开始绕 y 轴旋转,然后回到 z (这是有道理的,因为我有 z_rot += y_prime
。如何我可以围绕z旋转它并计算z'吗?
public void transform(float[] vertices_in, float[] vertices_out){
// perform your transformation
int length = vertices_in.length;
float[] transformMatrix =
{
r11, r12, r13, tx,
r21, r22, r23, ty,
r31, r32, r33, tz,
0, 0, 0, 1
};
// Fill in the empty verticesout vector
for(int i = 0; i < vertices_in.length; i++)
{
vertices_out[i] = vertices_in[i];
}
// loop through and set the new matrix (after translation)
// because
// 1 0 0 0
// 0 1 0 0
// 0 0 1 0
// X Rotation
for(int i = 0; i < vertices_out.length; i += 3)
{
vertices_out[i+1] = vertices_out[i+1] * (float)Math.cos(xRot) - vertices_out[i+2] * (float)Math.sin(xRot); //New Y
vertices_out[i+2] = vertices_out[i+1] * (float)Math.sin(xRot) + vertices_out[i+2] * (float)Math.cos(xRot); //New Z
}
// Y Rotation
for(int i = 0; i < vertices_out.length; i += 3)
{
vertices_out[i] = vertices_out[i] * (float)Math.cos(yRot) + vertices_out[i+2] * (float)Math.sin(yRot);
vertices_out[i+2] = vertices_out[i]*-(float)Math.sin(yRot) + vertices_out[i+2]*(float)Math.cos(yRot);
}
// Z Rotation
for(int i = 0; i < vertices_out.length; i += 3)
{
vertices_out[i] = vertices_out[i] * (float)Math.cos(zRot) - vertices_out[i+1] * (float)Math.sin(zRot);
vertices_out[i+1] = vertices_out[i] * (float)Math.sin(zRot) + vertices_out[i+1] * (float)Math.cos(zRot);
}
// Translation & Scaling
for(int i = 0; i < vertices_in.length; i+=3)
{
vertices_out[i] = vertices_out[i] * transformMatrix[0] + transformMatrix[3]; //x'
vertices_out[i+1] = vertices_out[i+1] * transformMatrix[5] + transformMatrix[7]; //y'
vertices_out[i+2] = vertices_out[i+2] * transformMatrix[10] + transformMatrix[11]; //z'
}
}
@Override
public void mouseDragged(MouseEvent e)
{
if(rotating)
{
float XX = (e.getX()-windowWidth*0.5f)*orthoX/windowWidth;
float YY = -(e.getY()-windowHeight*0.5f)*orthoX/windowWidth;
float x_prime = (StartXX - XX);
float y_prime = (StartYY - YY);
if(rightMouseClick)
{
zRot += y_prime/50;
}
else
{
xRot += y_prime/50;
yRot += x_prime/50;
StartYY = YY;
StartXX = XX;
}
}
}
最佳答案
所有这些旋转都使用不一致的中间状态。例如(我只是替换了较短的变量名称)。
y = y * (float)Math.cos(xRot) - z * (float)Math.sin(xRot); //New Y
z = y * (float)Math.sin(xRot) + z * (float)Math.cos(xRot); //New Z
第一行是正确的。然而,第二行在应该使用旧的 y
时已经使用了新的 y。因此,您必须将旧变量保存在某个地方才能使其工作。这同样适用于所有其他轮换。
其余代码看起来没问题。
关于java - 如何在不使用 glRotateF 内置函数的情况下在 JOGL 中绕 Z 轴旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39812922/
我正在编写国际象棋人工智能程序,并且在实现棋子方格表时遇到了问题。由于我只想每边有一张正方形 table ,因此我需要一个函数来翻转保存 x 轴值的一维数组。例如,这个数组: [ 2, 4, 5, 3
在应用程序中,在尝试使用触摸旋转对象时,我注意到一段时间后对象的位置发生了漂移(没有应用任何平移!!)。旋转仅围绕 z 轴,工作正常,但仅在旋转几次后才会发生漂移。 ds 将用于进行翻译(使用上下按钮
我正在尝试构建金字塔并为其设置动画。问题是在围绕 X 轴旋转它之后,我尝试围绕金字塔的高度(Y 轴)旋转它,但我每次都在移动。我基本上尝试了每个 transform-origin 选项,但它不起作用。
我需要绕其 x 轴(或 y 轴)旋转图像。我可以使用 avisynth 轻松创建这样的动画,但现在我需要使用 Python 的 moviepy 模块来实现该效果。我可以使用以下脚本轻松旋转图像,但需要
我有一个图像被分成两个相等的部分。我正在尝试在悬停时围绕 y 轴将图像的右侧部分旋转 -180°(逆时针)。 问题是有时(随机)图像旋转 180°(顺时针)而不是 -180°(逆时针)。这背后的原因可
如何使用CGAffineTransform(或其他)绕其Y轴旋转UIView?例如,我尝试过: self.image.transform = CGAffineTransform(rotationAng
我正在尝试围绕 y 轴旋转查看器。我有一个名为 tranform_eye() 的函数,它将计算 eyex、eyey 和 eyez 的下一个位置更新。 谁能帮我弄清楚如何计算 eyex、eyey 和 e
我无法解决我遇到的一个奇怪的错误,想知道是否有其他人遇到过类似的问题或可以提供解决方案。 我正在使用 javascript 访问 iOS 设备上的陀螺仪,并且对围绕 z 轴的旋转很感兴趣;我想要设备平
Qt 使用 3x3 变换矩阵进行透视变换和仿射变换。如果矩阵的最后一行等于 [0 0 1],则矩阵被认为是仿射的。由于这个原因,x 轴和 y 轴旋转矩阵是“非仿射”和透视失真结果。但还有进一步的影响。
我是一名优秀的程序员,十分优秀!