मैं quaternions से 3D मॉडल पर arcball रोटेशन, विशेष रूप से आईओएस पर GLKit प्रयोग करने के लिए एक सरल कार्यान्वयन के लिए देख रहा हूँ। अब तक, मैं निम्नलिखित स्रोतों की जांच की है:Arcball रोटेशन (आईओएस GLKit का प्रयोग करके)
मैं भी here और here से स्रोत कोड और गणित समझने की कोशिश कर रहा हूँ। मैं अपनी वस्तु को घुमा सकता हूं लेकिन यह कुछ कोणों पर चारों ओर कूदता रहता है, इसलिए मुझे डर है कि जिम्बल लॉक खेल रहा है। मैं घूर्णन को नियंत्रित करने के लिए इशारा पहचानकर्ताओं का उपयोग कर रहा हूं (पैन जेस्चर रोल और यॉ को प्रभावित करते हैं, इशारा करते हुए इशारे को पिच प्रभावित करते हैं)। मैं quaternion हैंडलिंग के साथ ही मॉडलव्यू मैट्रिक्स परिवर्तन के लिए अपने कोड संलग्न कर रहा हूँ।
चर:
GLKQuaternion rotationE;
Quaternion हैंडलिंग:
- (void)rotateWithXY:(float)x and:(float)y
{
const float rate = M_PI/360.0f;
GLKVector3 up = GLKVector3Make(0.0f, 1.0f, 0.0f);
GLKVector3 right = GLKVector3Make(1.0f, 0.0f, 0.0f);
up = GLKQuaternionRotateVector3(GLKQuaternionInvert(self.rotationE), up);
self.rotationE = GLKQuaternionMultiply(self.rotationE, GLKQuaternionMakeWithAngleAndVector3Axis(x*rate, up));
right = GLKQuaternionRotateVector3(GLKQuaternionInvert(self.rotationE), right);
self.rotationE = GLKQuaternionMultiply(self.rotationE, GLKQuaternionMakeWithAngleAndVector3Axis(y*rate, right));
}
- (void)rotateWithZ:(float)z
{
GLKVector3 front = GLKVector3Make(0.0f, 0.0f, -1.0f);
front = GLKQuaternionRotateVector3(GLKQuaternionInvert(self.rotationE), front);
self.rotationE = GLKQuaternionMultiply(self.rotationE, GLKQuaternionMakeWithAngleAndVector3Axis(z, front));
}
Modelview मैट्रिक्स परिवर्तन (अंदर ड्रा लूप):
// Get Quaternion Rotation
GLKVector3 rAxis = GLKQuaternionAxis(self.transformations.rotationE);
float rAngle = GLKQuaternionAngle(self.transformations.rotationE);
// Set Modelview Matrix
GLKMatrix4 modelviewMatrix = GLKMatrix4Identity;
modelviewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -0.55f);
modelviewMatrix = GLKMatrix4Rotate(modelviewMatrix, rAngle, rAxis.x, rAxis.y, rAxis.z);
modelviewMatrix = GLKMatrix4Scale(modelviewMatrix, 0.5f, 0.5f, 0.5f);
glUniformMatrix4fv(self.sunShader.uModelviewMatrix, 1, 0, modelviewMatrix.m);
किसी भी मदद की बहुत सराहना की जाती है, लेकिन मैं इसे यथासंभव सरल रखना चाहता हूं और जीएलकिट से चिपकना चाहता हूं।
शानदार जवाब देने के लिए डाल दिया आशा है, यह पूरी तरह से काम किया। यह quaternions में मेरा पहला उद्यम है, तो स्पष्ट स्पष्टीकरण की सराहना की है - धन्यवाद! मैंने आपके प्रश्न को (1) में उठाए गए बिंदु को स्पष्ट करने के लिए संपादित किया है, हालांकि इशारा को "पैन" (आईओएस सम्मेलन) नाम दिया गया है, यह वास्तव में मेरे मॉडल के घूर्णन को नियंत्रित करता है। –