저는 XNA와 협력하여 현재 미래의 게임에 사용할 수있는 좋은 핵심을 구축하고 있습니다. 나는 다음을 코딩하는 방법을 모르기 때문에XNA - 트리 렌더링 및 변환 렌더링
내 렌더링 트리를 완료 할 수 없습니다 :
(I OpenGL을 많이 작업하는 데 사용하고, 그래서이 코드를 가장 빠른 상당 찾고 있어요 난 당신이 수행해야하는 worldMatrix 암시 어디서나 액세스 할 수 없음을 이해하고
public void DrawRecursively(GameTime deltaTime, Matrix worldMatrix)
{
Matrix backup = worldMatrix;
// TRANSLATE HERE.
// ROTATE HERE.
this.Draw(deltaTime);
foreach (ComponentInterface child in childs)
{
child.DrawRecursively(deltaTime, worldMatrix);
}
worldMatrix = backup;
}
:)
public void DrawRecursively(GameTime deltaTime)
{
glPushMatrix();
/* these 3 lines are what i didn't figure out with XNA */
glTranslate3f(position[0], position[1], position[2]);
glRotatef(theta, 0.0f, 1.0f, 0.0f);
glRotatef(phi, 1.0f, 0.0f, 0.0f);
this.Draw(deltaTime);
foreach (ComponentInterface child in childs)
{
child.DrawRecursively(deltaTime);
}
glPopMatrix();
}
나의 현재 시도는이 같은 것입니다 그것에 대한 참조. 어떻게 변환하고 회전합니까? 그리고 내 worldMatrix
백업이 glPushMatrix
/PopMatrix
블록과 동일한 작업을 수행하는 올바른 방법입니까?
감사합니다,
닉
편집 :
내가이 여전히 작동하지 않는 말했다되고, 앞으로 몇 단계를 만들기 위해 관리 생각합니다.
public void DrawRecursively(GameTime deltaTime, BasicEffect effect)
{
Matrix worldMatrix = effect.World;
Matrix backup = worldMatrix;
worldMatrix = worldMatrix * Matrix.CreateTranslation(position.ToVector3());
worldMatrix = worldMatrix * Matrix.CreateRotationY(theta);
worldMatrix = worldMatrix * Matrix.CreateRotationX(phi);
effect.Parameters["xWorld"].SetValue(worldMatrix);
this.Draw(deltaTime);
foreach (ComponentInterface child in childs)
{
child.DrawRecursively(deltaTime, effect);
}
effect.Parameters["xWorld"].SetValue(backup);
}
effect.Parameters["xWorld"]
분명 나에게 널 포인터 그래서 SetValue
를 반환 나에게 액세스 위반이 발생합니다 : 하나님은 내가 OpenGL을 그리워하고 모든 자세한 문서는 MSDN 나에게 많은 정보를 제공하지 않습니다 ... 은 여기 내 최신 방법입니다 오류. 디버거에 따라 double 인스턴스가 확인되고 effect 인스턴스가 올바르게 초기화됩니다.
올바른 방법인가요? 다시
편집 : 당신의 도움에
덕분에, 나는 성공에 조금 가까운,하지만 삼각형은 여전히 정적 및 습관의 방향 각도를 증가하는 경우에도 회전.
public void DrawRecursively(GameTime deltaTime, BasicEffect effect)
{
Matrix worldMatrix = effect.World;
Matrix backup = worldMatrix;
effect.World = worldMatrix * Matrix.CreateScale(scale)
* Matrix.CreateRotationX(orientation.X)
* Matrix.CreateRotationX(orientation.Y)
* Matrix.CreateRotationX(orientation.Z)
* Matrix.CreateTranslation(position.ToVector3());
this.Draw(deltaTime);
foreach (ComponentInterface child in childs)
{
child.DrawRecursively(deltaTime, effect);
}
effect.World = backup;
}
더 이상 작동하지 않지만 테스트 삼각형은 의도 한대로 회전하지 않습니다. 업데이트 함수에서 theta를 증가시키고 디버거는 CreateRotation이 유효한 쎄 타의 증분으로 호출됨을 보여줍니다. – NGauthier
@NGauthier : 다른 방향으로 CreateRotationX를 세 번 사용하고 있습니다. CreateFromYawPitchRoll (y, x, z)를 사용하여 일부 행렬 곱셈을 저장할 수 있습니다. – Kyte