コード例 #1
0
        void IMouseHandler.canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDownFlag && ((e.Button & this.lastBindingMouseButtons) != MouseButtons.None))
            {
                if (!cameraState.IsSameState(this.camera))
                {
                    SetCamera(this.camera.Position, this.camera.Target, this.camera.UpVector);
                }

                this._endPosition = GetArcBallPosition(e.X, e.Y);
                var cosAngle = _startPosition.dot(_endPosition) / (_startPosition.length() * _endPosition.length());
                if (cosAngle > 1.0f)
                {
                    cosAngle = 1.0f;
                }
                else if (cosAngle < -1)
                {
                    cosAngle = -1.0f;
                }
                var angle = MouseSensitivity * (float)(Math.Acos(cosAngle) / Math.PI * 180);
                _normalVector = _startPosition.cross(_endPosition).normalize();
                if (!
                    ((_normalVector.x == 0 && _normalVector.y == 0 && _normalVector.z == 0) ||
                     float.IsNaN(_normalVector.x) || float.IsNaN(_normalVector.y) || float.IsNaN(_normalVector.z)))
                {
                    _startPosition = _endPosition;

                    mat4 newRotation = glm.rotate(angle, _normalVector);
                    this.totalRotation = newRotation * totalRotation;
                }
            }
        }
コード例 #2
0
        public AnnulusModel(float radius, float thickness, uint sliceCount, uint secondSliceCount)
        {
            {
                var positions = new vec3[sliceCount * secondSliceCount];
                int t         = 0;
                var y         = new vec3(0, 1, 0);
                for (int i = 0; i < sliceCount; i++)
                {
                    double di     = 2 * Math.PI * i / sliceCount;
                    var    center = new vec3(radius * (float)Math.Sin(di), 0, radius * (float)Math.Cos(di));
                    float  length = center.length();
                    center = center.normalize();
                    for (int j = 0; j < secondSliceCount; j++)
                    {
                        double dj = 2 * Math.PI * j / secondSliceCount;
                        positions[t++] = center * (length - thickness * (float)Math.Cos(dj))
                                         + y * (thickness * (float)Math.Sin(dj));
                    }
                }
                BoundingBox box = positions.Move2Center();
                this.positions = positions;
                this.modelSize = box.MaxPosition - box.MinPosition;
            }
            {
                var  indexes = new uint[sliceCount * (secondSliceCount * 3 + secondSliceCount * 3)];
                uint t       = 0;
                for (uint i = 0; i < sliceCount; i++)
                {
                    for (uint j = 0; j < secondSliceCount; j++)
                    {
                        indexes[t++] = i * secondSliceCount + j;
                        indexes[t++] = i * secondSliceCount + (j + 1) % secondSliceCount;
                        indexes[t++] = (i * secondSliceCount + secondSliceCount + (j + 1) % secondSliceCount) % (sliceCount * secondSliceCount);

                        indexes[t++] = i * secondSliceCount + j;
                        indexes[t++] = (i * secondSliceCount + secondSliceCount + (j + 1) % secondSliceCount) % (sliceCount * secondSliceCount);
                        indexes[t++] = (i * secondSliceCount + secondSliceCount + j) % (sliceCount * secondSliceCount);
                    }
                }
                this.indexes = indexes;
            }
        }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(string.Format("back:{0}|{3:0.00},up:{1}|{4:0.00},right:{2}|{5:0.00}",
                          back, up, right, back.length(), up.length(), right.length()));
 }
コード例 #4
0
ファイル: DiskModel.cs プロジェクト: winterlutos/CSharpGL
        public DiskModel(float radius, float holeRadius, float thickness, uint sliceCount, uint secondSliceCount)
        {
            uint upPlane, downPlane;

            uint[] upSphere   = new uint[sliceCount];
            uint[] downSphere = new uint[sliceCount];
            {
                var  positions = new vec3[sliceCount * secondSliceCount + sliceCount + sliceCount];
                uint t         = 0;
                var  y         = new vec3(0, 1, 0);
                for (int i = 0; i < sliceCount; i++)
                {
                    upSphere[i] = t;
                    double di     = 2 * Math.PI * i / sliceCount;
                    var    center = new vec3(radius * (float)Math.Sin(di), 0, radius * (float)Math.Cos(di));
                    float  length = center.length();
                    center = center.normalize();
                    for (int j = 0; j < secondSliceCount; j++)
                    {
                        double dj = Math.PI / 2 + Math.PI * j / (secondSliceCount - 1);
                        positions[t++] = center * (length - thickness * (float)Math.Cos(dj))
                                         + y * (thickness * (float)Math.Sin(dj));
                    }
                    downSphere[i] = t - 1;
                }
                upPlane = t;
                for (int i = 0; i < sliceCount; i++)
                {
                    double di = 2 * Math.PI * i / sliceCount;
                    positions[t++] = new vec3(holeRadius * (float)Math.Sin(di), thickness, holeRadius * (float)Math.Cos(di));
                }
                downPlane = t;
                for (int i = 0; i < sliceCount; i++)
                {
                    double di = 2 * Math.PI * i / sliceCount;
                    positions[t++] = new vec3(holeRadius * (float)Math.Sin(di), -thickness, holeRadius * (float)Math.Cos(di));
                }
                BoundingBox box = positions.Move2Center();
                this.positions = positions;
                this.modelSize = box.MaxPosition - box.MinPosition;
            }
            {
                var indexes = new uint[sliceCount * (secondSliceCount - 1) * 2 * 3
                                       + sliceCount * 2 * 3 + sliceCount * 2 * 3
                                       + sliceCount * 2 * 3];
                uint t = 0;
                for (uint i = 0; i < sliceCount; i++)
                {
                    for (uint j = 0; j < secondSliceCount - 1; j++)
                    {
                        indexes[t++] = i * secondSliceCount + j;
                        indexes[t++] = i * secondSliceCount + (j + 1) % secondSliceCount;
                        indexes[t++] = (i * secondSliceCount + secondSliceCount + (j + 1) % secondSliceCount) % (sliceCount * secondSliceCount);

                        indexes[t++] = i * secondSliceCount + j;
                        indexes[t++] = (i * secondSliceCount + secondSliceCount + (j + 1) % secondSliceCount) % (sliceCount * secondSliceCount);
                        indexes[t++] = (i * secondSliceCount + secondSliceCount + j) % (sliceCount * secondSliceCount);
                    }
                }
                for (uint i = 0; i < sliceCount; i++)
                {
                    indexes[t++] = upPlane + i;
                    indexes[t++] = upSphere[i];
                    indexes[t++] = upPlane + (i + 1) % sliceCount;

                    indexes[t++] = upPlane + (i + 1) % sliceCount;
                    indexes[t++] = upSphere[i];
                    indexes[t++] = upSphere[(i + 1) % sliceCount];
                }
                for (uint i = 0; i < sliceCount; i++)
                {
                    indexes[t++] = downPlane + i;
                    indexes[t++] = downPlane + (i + 1) % sliceCount;
                    indexes[t++] = downSphere[i];

                    indexes[t++] = downPlane + (i + 1) % sliceCount;
                    indexes[t++] = downSphere[(i + 1) % sliceCount];
                    indexes[t++] = downSphere[i];
                }
                for (uint i = 0; i < sliceCount; i++)
                {
                    indexes[t++] = upPlane + i;
                    indexes[t++] = upPlane + (i + 1) % sliceCount;
                    indexes[t++] = downPlane + i;

                    indexes[t++] = downPlane + i;
                    indexes[t++] = upPlane + (i + 1) % sliceCount;
                    indexes[t++] = downPlane + (i + 1) % sliceCount;
                }
                this.indexes = indexes;
            }
        }