久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

WPF中3D旋轉(zhuǎn)的實(shí)現(xiàn)

 xyjackxjw 2013-05-09

WPF中3D旋轉(zhuǎn)的實(shí)現(xiàn)

分類: WPF 3D3365人閱讀評(píng)論(3)收藏舉報(bào)

關(guān)于3D旋轉(zhuǎn)的原理,請(qǐng)看Daniel Lehenbauer的文章

《Rotating the Camera with the Mouse》

http:///trackball.htm

 

里面非常清楚的講解了原理和方法,,很受用,。

 

相關(guān)代碼:

 

2.1 Finding the Point on the Sphere

private Vector3D ProjectToTrackball(Double width, Double height, Point point)
        {
            Double x = point.X / (width / 2);    // Scale so bounds map to [0,0] - [2,2]
            Double y = point.Y / (height / 2);

            x = x - 1;                           // Translate 0,0 to the center
            y = 1 - y;                           // Flip so +Y is up instead of down

            Double z2 = 1 - x * x - y * y;       // z^2 = 1 - x^2 - y^2
            Double z = z2 > 0 ? Math.Sqrt(z2) : 0;
            return new Vector3D(x, y, z);
        }

 

2.2 Rotating Between the Points

        private void Rotate(Point currentPosition)
        {
            Vector3D currentPosition3D = ProjectToTrackball(EventSource.ActualWidth, EventSource.ActualHeight, currentPosition);

            Vector3D axis = Vector3D.CrossProduct(_previousRotPosition3D, currentPosition3D);
            Double angle = Vector3D.AngleBetween(_previousRotPosition3D, currentPosition3D);

            Rotate(axis, angle);

            _previousRotPosition3D = currentPosition3D;
        }

 

        private void Rotate(Vector3D axis, Double angle)
        {
            Quaternion delta = new Quaternion(axis, -angle * _rotScale);

            Quaternion q = new Quaternion(_axisAngleRotation3D.Axis, _axisAngleRotation3D.Angle);

            q *= delta;

            Vector3D zeorVec = new Vector3D(0.0, 0.0, 0.0);
            if (Vector3D.Equals(q.Axis, zeorVec))
                return;

            _axisAngleRotation3D.Axis = q.Axis;
            _axisAngleRotation3D.Angle = q.Angle;
        }

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多