2014-03-26 2 views
2

OpenGL/SceneKit/CoreAnimation 환경에서 변형에 문제가 있습니다. 나는 나의 LED 장면을 가지고있다. 또한 각 LED와 교차하는 평면을 만들었습니다. 이 비행기는 미래에 투명해질 것이며 일단 billboarding 문제가 해결되면 LED 주위에 밝은 원을 그리는 데 사용될 것입니다. 카메라가 장면의 중심이 아닌 3D 공간에서 2D 평면을 빌리기

Default Behavior

나는 카메라에 비행기 광고판을 만들려고 노력하고 있습니다. 내가 가지고있는 문제는 내가 만든 장면과 같은 종류의 변형을 정확하게 찾을 수 없다는 것입니다.

내 mouseDragged : 메서드에서 X 회전 및 Y 회전 행렬을 반전하고이를 연결하여 최종 정형으로 사용하여 LED의 정 회전을 반전시켜 비행기가 항상 카메라를 마주 보도록 만듭니다. 나는 두 축을 이동할 때 걸리는 것처럼

-(void)mouseDragged:(NSEvent *)theEvent 
{ 

NSPoint winp = [theEvent locationInWindow]; 
NSPoint p  = [sceneView convertPoint:winp fromView:nil]; 

mouseDraggedLocation = p; 

//****************** TRANSFROM INIT **************************************** 

CATransform3D localProjectionTransform; 
CATransform3D translatedProjectionTransformX; 
CATransform3D translatedProjectionTransformY; 
CATransform3D translatedProjectionTransformFinal; 

CATransform3D rotatedProjectionTransformX; 
CATransform3D rotatedProjectionTransformY; 
CATransform3D rotatedProjectionTransformFinal; 

CATransform3D checkedProjectionTransform; 
CATransform3D translatedProjectionTransformZ; 
CATransform3D translationOnlyMatrix; 


CATransform3D tempTransform; 

//****************** TRANSFROM INIT **************************************** 

// Figure out Angle 

angleX = mouseDraggedLocation.x - mouseOldLocation.x; 
angleY = mouseDraggedLocation.y - mouseOldLocation.y; 

//********************************PLAYING WITH TRANSFORMS**************************** 




// X transform 
rotatedProjectionTransformX = CATransform3DMakeRotation(angleX * ROTATION_FACTOR, 0, 1, 0); 
// Y transform 
rotatedProjectionTransformY = CATransform3DMakeRotation(angleY * ROTATION_FACTOR, -1.0f, 0.0f, 0.0f); 
rotatedProjectionTransformFinal = CATransform3DConcat(rotatedProjectionTransformX, rotatedProjectionTransformY); 

translatedProjectionTransformX = CATransform3DMakeTranslation(0, angleX * ROTATION_FACTOR, 0); 
translatedProjectionTransformY = CATransform3DMakeTranslation(-1 *(angleY * ROTATION_FACTOR), 0, 0); 
translatedProjectionTransformFinal = CATransform3DConcat(translatedProjectionTransformX, translatedProjectionTransformY); 

         //      rootNode 
         //       | 
         //      ledArrayNode 
         //     /     \ 
         //  outlinePlaneNode (s)  LEDGeomNode(s) 


// OH GOD PLEASE DON'T HATE ME FOR THIS, it chooses nodes that aren't Outline nodes, just disregard as crap test coding. 

for (SCNNode *NodeTemp in [ledArrayNode childNodes]) { 

    if ([NodeTemp.name rangeOfString:@"O"].location == NSNotFound) { 
     localProjectionTransform = NodeTemp.transform; 
     NodeTemp.transform = CATransform3DConcat(localProjectionTransform, rotatedProjectionTransformFinal); 
    } else { 

    } 



} 


// This is what does the rotation with the outline planes, the previous loop did normal rotations for the LEDGeom Nodes 

tempTransform = CATransform3DInvert(rotatedProjectionTransformFinal); 

for (SPCLedGeom *LEDTemp1 in LED_Array) { 
    localProjectionTransform = LEDTemp1.LED_Outline_Plane_Node.transform; 


    LEDTemp1.LED_Outline_Plane_Node.transform = CATransform3DConcat(localProjectionTransform, tempTransform); 
} 




mouseOldLocation.x = mouseDraggedLocation.x; 
mouseOldLocation.y = mouseDraggedLocation.y; 


} 

난 그냥 함께 축 중 하나에 움직임을 고정하지만, 경우는 일반적으로 그 자체로 축 중 하나를 잘 작동,

x-axis goofery

는하지만, 그것은 본다 Y 축이 "위로"(약 Y 축에서 이동할 때 시계 방향/반 시계 방향 운동으로 x 축을 따라 회전 할 때) 약 2 회 완전 회전하고 x 축은 "꺼짐"이며 이전처럼 움직였다.

billboarding에 대해 읽었을 때 jist는 회전/변형 행렬에서 번역 측면을 가져 와서 사용했지만 그 예에서는 카메라가 장면의 중심으로 간주되는 반면에 SceneKit과 내가하는 일에 대해, 중심은 LED 배열의 중심이며 mouseDragged : 메서드에서 볼 수있는 것처럼 LED 노드를 이동하는 동안 카메라는 고정되어 있습니다.

+0

그래서 모든 비행기가 항상 카메라/시점을 바라보기를 원하십니까? –

+0

그게 그 계획이에요. - 업데이트하지 않아 죄송합니다. 알림을 올바르게 설정하지 않았습니다. – Ptier

+0

제약 조건을 보았습니까? –

답변

2

가장 간단한 것은 SCNConstraint를 사용하는 것입니다. Here it is in the WWDC 2013 session. 그냥보고 다운로드 받아야합니다. 어떤 경우에도 제약 조건을 사용하여 평면을 카메라를 향한 상태로 유지할 수 있습니다. 비행기가 투명하기 때문에 LED를 감싸는 데 실제 보이는 것이 거의 없습니다. 나는 이것이 꽤 좋은 선택이라고 생각한다.

nodeA.constraints = @[SCNLookAtConstraint lookAtConstraintWithTarget:nodeB]; 

이 경우 nodeB는 cameraNode이고 nodeA는 모든 평면을 포함하는 노드입니다.

감사합니다. David Rönnqvist 오른쪽 방향의 화살표는

관련 문제