2012-09-27 25 views
7

के साथ एक पूर्ण 3 डी कंकाल बनाएं, यह यूनी में मेरे पहले ग्राफिक्स विषय के लिए है, और कार्यान्वयन के कुछ हिस्सों सिर्फ मेरे लिए काम नहीं कर रहे हैं। मैं जोड़ों को सही तरीके से आकर्षित करने के लिए प्राप्त कर सकता हूं, लेकिन मैं जोड़ों के बीच 'हड्डियों' में रखे एक समारोह को लिखने की कोशिश कर रहा हूं। इस बिंदु पर हड्डियां केवल cubes हैं जो आयताकार प्रिज्म के रूप में परिवर्तित हो जाती हैं, बाद में मैं ब्लेंडर या कुछ से उचित मॉडल पेश करने का प्रयास करूंगा।किनेक्ट एसडीके

मेरी समस्या घूर्णन के साथ है। लगभग 5 घंटे या उसके बाद मेरे साथी और मेरे पास यह काम कर रहा है, लेकिन जैसे ही आप अपनी बाहों या पैरों को क्यूब्स के बाहर ले जाते हैं और अजीब लगते हैं। किसी भी सहायता की सराहना की जाएगी। नीचे वह कार्य है जो हड्डियों को आकर्षित करने का प्रयास करता है।

private void DrawBone(Skeleton skeleton, JointType jointType0, JointType jointType1) 
{ 
    Joint joint0 = skeleton.Joints[jointType0]; 
    Joint joint1 = skeleton.Joints[jointType1]; 

    // If we can't find either of these joints, exit 
    if (joint0.TrackingState == JointTrackingState.NotTracked || 
     joint1.TrackingState == JointTrackingState.NotTracked) 
    { 
     return; 
    } 

    // Don't draw if both points are inferred 
    if (joint0.TrackingState == JointTrackingState.Inferred && 
     joint1.TrackingState == JointTrackingState.Inferred) 
    { 
     return; 
    } 

    // We assume all drawn bones are inferred unless BOTH joints are tracked 
    if (joint0.TrackingState == JointTrackingState.Tracked && joint1.TrackingState == JointTrackingState.Tracked) 

     //jointvector(joint) takes a joint and returns a Vector2 with its position data, with the z invtred to work properly with directx11 
     Vector3 bonevector = Vector3.Subtract(jointVector(joint0), jointVector(joint1)); 
     //cubevector is supposed to describe the initial vector of a cube centred at (0,0,0) with a side length of 2. A fair amount of guesswork has gone into this bit. 
     Vector3 cubevector = new Vector3(0, 2, 0); 
     //midpoint of two joints 
     Vector3 transTest = Vector3.Divide(Vector3.Add(jointVector(joint0),jointVector(joint1)), 2); 
     //divide by two because our original cube has side length 2 
     float scaleFactor = Math.Abs(bonevector.Length()/cubevector.Length()); 

     //we haven't been taught quaternions in class or anything, but after a fair while searching for similar problems they seemed like the go-to option for rotations. 
     world = Matrix.Transformation(new Vector3(0, 0, 0), new Quaternion(0), new Vector3(0.05f, scaleFactor, 0.05f), new Vector3(0, 0, 0), new Quaternion(Vector3.Cross(cubevector, bonevector), (float)Math.Acos(Vector3.Dot(bonevector, cubevector))), transTest);  

     //view and proj are defined elsewhere and are working fine, it's just the world that is being lame   
     worldViewProj = world * view * proj; 
     worldViewProj.Transpose(); 
     sDXdata.context.UpdateSubresource(ref worldViewProj, sDXdata.constantBuffer); 
     //36 vertices of the cube (two triangles per face) defined elsewhere 
     sDXdata.context.Draw(36, 0); 
     return; 
+0

हाय विन्स, क्या आपको कभी यह चल रहा है? यह समझने में रुचि होगी कि आपने 3 डी में मॉडल कैसे प्रदर्शित किया। –

उत्तर

3

हड्डी झुकाव के लिए, की जाँच करें:

skeleton.BoneOrientations[joint.JointType] 

तो यह आपको एक BoneOrientation वर्ग

http://msdn.microsoft.com/en-us/library/microsoft.kinect.boneorientation.aspx

दे देंगे वहां से आप के रूप में या तो Quaternion/मैट्रिक्स, या तो में रोटेशन हो सकता है विश्व अंतरिक्ष, या पैरेंट हड्डी की जगह (स्किनिंग के लिए)

इसके अलावा, आप का उपयोग करें:

Quaternion.Identity; 

जो हो जाएगा (0,0,0,1)

1

:

new Quaternion(0) 

यह एक 0 वेक्टर, नहीं रोटेशन के लिए एक वैध चौका, इस्तेमाल होता है यद्यपि यह थोड़ी देर पहले पूछा गया था, इसके लिए यह क्या योग्य है, मुझे लगता है कि जब आप अपने कोण की गणना करते हैं तो भी एक त्रुटि होती है। आपके पास:

(float)Math.Acos(Vector3.Dot(bonevector, cubevector) 

मुझे लगता है कि आप की जरूरत:

(float)Math.Acos(Vector3.Dot(bonevector, cubevector)/(bonevector.Length() * 
cubevector.Length())) 

Here गणित की एक अच्छी छोटी उदाहरण है। बाहर MSDN पेज अधिक जानकारी के लिए

(float)Math.Acos(Vector3.Dot(bonevector.Normalize(), cubevector.Normalize())) 

की जांच: तुम भी उन्हें इकाई वैक्टर कर सकता है, तो वे एक की लंबाई है और विभाजन के साथ परेशान नहीं।

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^