0
나는 태양과 지구라는 두 개의 행성을 가지고있다. 나는 그들로 하여금 자신들의 축을 중심으로 회전하고, 동시에 행성의 궤도를 돌리기를 바랍니다.행렬 곱셈 - 행성을 자신의 축으로 돌리고 부모의 궤도를 돌리는 방법?
이 두 가지 동작을 개별적으로 수행 할 수는 있지만, 어떻게 조합 할 것인가는 혼란 스럽습니다.
void planet::render() {
mat4 axisPos = mat4(1.0f);
axialRotation = rotate(axisPos, axisRotationSpeedConstant, vec3(0.0f, 1.0f, 0.0f));
if (hostPlanet != NULL) {
mat4 hostTransformPosition = mat4(1.0f);
hostTransformPosition[3] = hostPlanet->getTransform()[3];
orbitalSpeed += orbitalSpeedConstant;
orbitRotation = rotate(hostTransformPosition, orbitalSpeed, vec3(0.0f, 1.0f, 0.0f));
orbitRotation = translate(orbitRotation, vec3(distanceFromParent, 0.0f, 0.0f));
//rotTransform will make them spin on their axis, but not orbit their parent planet
mat4 rotTransform = transform * axialRotation;
//transform *= rotTransform;
//orbitRotation will make the planet orbit, but it won't spin on it's own axis.
transform = orbitRotation;
}
else {
transform *= axialRotation;
}
glUniform4fv(gColLoc, 1, &color[0]);
glUniformMatrix4fv(gModelToWorldTransformLoc, 1, GL_FALSE, &getTransform()[0][0]);
glDrawArrays(GL_LINES, 0, NUMVERTS);
};