当前位置: 首页>>代码示例>>C#>>正文


C# Vector3.normalize方法代码示例

本文整理汇总了C#中System.Vector3.normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.normalize方法的具体用法?C# Vector3.normalize怎么用?C# Vector3.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Vector3的用法示例。


在下文中一共展示了Vector3.normalize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getRadiance

 public Color getRadiance(ShadingState state)
 {
     // don't use these - gather lights for sphere of directions
     // gather lights
     state.initLightSamples();
     state.initCausticSamples();
     Vector3 v = state.getRay().getDirection();
     v.negate();
     Vector3 h = new Vector3();
     Vector3 t = state.getBasis().transform(new Vector3(0, 1, 0));
     Color diff = Color.black();
     Color spec = Color.black();
     foreach (LightSample ls in state)
     {
         Vector3 l = ls.getShadowRay().getDirection();
         float dotTL = Vector3.dot(t, l);
         float sinTL = (float)Math.Sqrt(1 - dotTL * dotTL);
         // float dotVL = Vector3.dot(v, l);
         diff.madd(sinTL, ls.getDiffuseRadiance());
         Vector3.add(v, l, h);
         h.normalize();
         float dotTH = Vector3.dot(t, h);
         float sinTH = (float)Math.Sqrt(1 - dotTH * dotTH);
         float s = (float)Math.Pow(sinTH, 10.0f);
         spec.madd(s, ls.getSpecularRadiance());
     }
     Color c = Color.add(diff, spec, new Color());
     // transparency
     return Color.blend(c, state.traceTransparency(), state.getV(), new Color());
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:30,代码来源:Hair.cs

示例2: makeFromW

 public static OrthoNormalBasis makeFromW(Vector3 w)
 {
     OrthoNormalBasis onb = new OrthoNormalBasis();
     w.normalize(onb.w);
     if ((Math.Abs(onb.w.x) < Math.Abs(onb.w.y)) && (Math.Abs(onb.w.x) < Math.Abs(onb.w.z)))
     {
         onb.v.x = 0;
         onb.v.y = onb.w.z;
         onb.v.z = -onb.w.y;
     }
     else if (Math.Abs(onb.w.y) < Math.Abs(onb.w.z))
     {
         onb.v.x = onb.w.z;
         onb.v.y = 0;
         onb.v.z = -onb.w.x;
     }
     else
     {
         onb.v.x = onb.w.y;
         onb.v.y = -onb.w.x;
         onb.v.z = 0;
     }
     Vector3.cross(onb.v.normalize(), onb.w, onb.u);
     return onb;
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:25,代码来源:OrthoNormalBasis.cs

示例3: makeFromWV

 public static OrthoNormalBasis makeFromWV(Vector3 w, Vector3 v)
 {
     OrthoNormalBasis onb = new OrthoNormalBasis();
     w.normalize(onb.w);
     Vector3.cross(v, onb.w, onb.u).normalize();
     Vector3.cross(onb.w, onb.u, onb.v);
     return onb;
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:8,代码来源:OrthoNormalBasis.cs

示例4: DirectionalSpotlight

 public DirectionalSpotlight()
 {
     src = new Point3(0, 0, 0);
     dir = new Vector3(0, 0, -1);
     dir.normalize();
     basis = OrthoNormalBasis.makeFromW(dir);
     r = 1;
     r2 = r * r;
     radiance = Color.WHITE;
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:10,代码来源:DirectionalSpotlight.cs

示例5: Quaternion

        public Quaternion(float theta, float x, float y, float z)
        {
            data = new float[4];
            float sinAngle;
            theta = theta * 0.5f;
            Vector3 vn = new Vector3(x, y, z);
            vn.normalize();

            sinAngle = (float)Math.Sin(theta);

            data[1] = (vn.X * sinAngle);
            data[2] = (vn.Y * sinAngle);
            data[3] = (vn.Z * sinAngle);
            data[0] = (float)Math.Cos(theta);
        }
开发者ID:lvarvel,项目名称:aura,代码行数:15,代码来源:Quaternion.cs

示例6: update

 public bool update(ParameterList pl, SunflowAPI api)
 {
     src = pl.getPoint("source", src);
     dir = pl.getVector("dir", dir);
     dir.normalize();
     r = pl.getFloat("radius", r);
     basis = OrthoNormalBasis.makeFromW(dir);
     r2 = r * r;
     radiance = pl.getColor("radiance", radiance);
     return true;
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:11,代码来源:DirectionalSpotlight.cs

示例7: configBillboard

        protected void configBillboard(Vector3 position)
        {
            //Shamelessly stolen from http://www.lighthouse3d.com/opengl/billboarding/index.php?billSphe
            if (LockType == BillboardLockType.Cylindrical || LockType == BillboardLockType.Spherical)
            {
                float[] modelView = new float[16];
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glPushMatrix();
                //Gl.glLoadIdentity();
                Vector3 camera = CameraManager.Current.position;

                Vector3 difference = new Vector3(camera.X - position.X, 0, camera.Z - position.Z);
                Vector3 lookAt = new Vector3(0,0,1);
                difference.normalize();
                Vector3 up = lookAt.cross(difference);
                float angleCosine = lookAt.dot(difference);
                if ((angleCosine < 0.99990) && (angleCosine > -0.9999))
                    Gl.glRotatef((float)(Math.Acos(angleCosine) * 180/Math.PI), up.X, up.Y, up.Z);

                if (LockType == BillboardLockType.Spherical)
                {
                    Vector3 difference3d = camera - position;
                    difference3d.normalize();
                    angleCosine = difference3d.dot(difference);
                    if ((angleCosine < 0.99990) && (angleCosine > -0.9999))
                    {
                        if (difference3d.Y < 0)
                            Gl.glRotatef((float)(Math.Acos(angleCosine) * 180 / Math.PI), 1, 0, 0);
                        else
                            Gl.glRotatef((float)(Math.Acos(angleCosine) * 180 / Math.PI), -1, 0, 0);
                    }
                }
            }
        }
开发者ID:lvarvel,项目名称:aura,代码行数:34,代码来源:Billboard.cs

示例8: initSunSky

        private void initSunSky()
        {
            // perform all the required initialization of constants
            sunDirWorld.normalize();
            sunDir = basis.untransform(sunDirWorld, new Vector3());
            sunDir.normalize();
            sunTheta = (float)Math.Acos(MathUtils.clamp(sunDir.z, -1, 1));
            if (sunDir.z > 0)
            {
                sunSpectralRadiance = computeAttenuatedSunlight(sunTheta, turbidity);
                // produce color suitable for rendering
                sunColor = RGBSpace.SRGB.convertXYZtoRGB(sunSpectralRadiance.toXYZ().mul(1e-4f)).constrainRGB();
            }
            else
            {
                sunSpectralRadiance = new ConstantSpectralCurve(0);
            }
            // sunSolidAngle = (float) (0.25 * Math.PI * 1.39 * 1.39 / (150 * 150));
            float theta2 = sunTheta * sunTheta;
            float theta3 = sunTheta * theta2;
            float T = turbidity;
            float T2 = turbidity * turbidity;
            double chi = (4.0 / 9.0 - T / 120.0) * (Math.PI - 2.0 * sunTheta);
            zenithY = (4.0453 * T - 4.9710) * Math.Tan(chi) - 0.2155 * T + 2.4192;
            zenithY *= 1000; /* conversion from kcd/m^2 to cd/m^2 */
            zenithx = (0.00165 * theta3 - 0.00374 * theta2 + 0.00208 * sunTheta + 0) * T2 + (-0.02902 * theta3 + 0.06377 * theta2 - 0.03202 * sunTheta + 0.00394) * T + (0.11693 * theta3 - 0.21196 * theta2 + 0.06052 * sunTheta + 0.25885);
            zenithy = (0.00275 * theta3 - 0.00610 * theta2 + 0.00316 * sunTheta + 0) * T2 + (-0.04212 * theta3 + 0.08970 * theta2 - 0.04153 * sunTheta + 0.00515) * T + (0.15346 * theta3 - 0.26756 * theta2 + 0.06669 * sunTheta + 0.26688);

            perezY[0] = 0.17872 * T - 1.46303;
            perezY[1] = -0.35540 * T + 0.42749;
            perezY[2] = -0.02266 * T + 5.32505;
            perezY[3] = 0.12064 * T - 2.57705;
            perezY[4] = -0.06696 * T + 0.37027;

            perezx[0] = -0.01925 * T - 0.25922;
            perezx[1] = -0.06651 * T + 0.00081;
            perezx[2] = -0.00041 * T + 0.21247;
            perezx[3] = -0.06409 * T - 0.89887;
            perezx[4] = -0.00325 * T + 0.04517;

            perezy[0] = -0.01669 * T - 0.26078;
            perezy[1] = -0.09495 * T + 0.00921;
            perezy[2] = -0.00792 * T + 0.21023;
            perezy[3] = -0.04405 * T - 1.65369;
            perezy[4] = -0.01092 * T + 0.05291;

            int w = 32, h = 32;
            imageHistogram = new float[w][];
            for (int i = 0; i < imageHistogram.Length; i++)
                imageHistogram[i] = new float[h];
            colHistogram = new float[w];
            float du = 1.0f / w;
            float dv = 1.0f / h;
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    float u = (x + 0.5f) * du;
                    float v = (y + 0.5f) * dv;
                    Color c = getSkyRGB(getDirection(u, v));
                    imageHistogram[x][y] = c.getLuminance() * (float)Math.Sin(Math.PI * v);
                    if (y > 0)
                        imageHistogram[x][y] += imageHistogram[x][y - 1];
                }
                colHistogram[x] = imageHistogram[x][h - 1];
                if (x > 0)
                    colHistogram[x] += colHistogram[x - 1];
                for (int y = 0; y < h; y++)
                    imageHistogram[x][y] /= imageHistogram[x][h - 1];
            }
            for (int x = 0; x < w; x++)
                colHistogram[x] /= colHistogram[w - 1];
            jacobian = (float)(2 * Math.PI * Math.PI) / (w * h);
        }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:74,代码来源:SunSkyLight.cs

示例9: getSkyRGB

 private Color getSkyRGB(Vector3 dir)
 {
     if (dir.z < 0)
         return Color.BLACK;
     if (dir.z < 0.001f)
         dir.z = 0.001f;
     dir.normalize();
     double theta = Math.Acos(MathUtils.clamp(dir.z, -1, 1));
     double gamma = Math.Acos(MathUtils.clamp(Vector3.dot(dir, sunDir), -1, 1));
     double x = perezFunction(perezx, theta, gamma, zenithx);
     double y = perezFunction(perezy, theta, gamma, zenithy);
     double Y = perezFunction(perezY, theta, gamma, zenithY) * 1e-4;
     XYZColor c = ChromaticitySpectrum.get((float)x, (float)y);
     // XYZColor c = new ChromaticitySpectrum((float) x, (float) y).toXYZ();
     float X = (float)(c.getX() * Y / c.getY());
     float Z = (float)(c.getZ() * Y / c.getY());
     return RGBSpace.SRGB.convertXYZtoRGB(X, (float)Y, Z);
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:18,代码来源:SunSkyLight.cs

示例10: getTangent

 private Vector3 getTangent(int line, int v0, float v)
 {
     Vector3 vcurr = new Vector3(points[v0 + 3] - points[v0 + 0], points[v0 + 4] - points[v0 + 1], points[v0 + 5] - points[v0 + 2]);
     vcurr.normalize();
     if (line == 0 || line == numSegments - 1)
         return vcurr;
     if (v <= 0.5f)
     {
         // get previous segment
         Vector3 vprev = new Vector3(points[v0 + 0] - points[v0 - 3], points[v0 + 1] - points[v0 - 2], points[v0 + 2] - points[v0 - 1]);
         vprev.normalize();
         float t = v + 0.5f;
         float s = 1 - t;
         float vx = vprev.x * s + vcurr.x * t;
         float vy = vprev.y * s + vcurr.y * t;
         float vz = vprev.z * s + vcurr.z * t;
         return new Vector3(vx, vy, vz);
     }
     else
     {
         // get next segment
         v0 += 3;
         Vector3 vnext = new Vector3(points[v0 + 3] - points[v0 + 0], points[v0 + 4] - points[v0 + 1], points[v0 + 5] - points[v0 + 2]);
         vnext.normalize();
         float t = 1.5f - v;
         float s = 1 - t;
         float vx = vnext.x * s + vcurr.x * t;
         float vy = vnext.y * s + vcurr.y * t;
         float vz = vnext.z * s + vcurr.z * t;
         return new Vector3(vx, vy, vz);
     }
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:32,代码来源:Hair.cs

示例11: transformVector

        public Vector3 transformVector(Vector3 vec)
        {
            Vector3 vn = new Vector3(ref vec);
            vn.normalize();

            Quaternion vecQuat = new Quaternion();
            Quaternion resQuat = new Quaternion();
            vecQuat.X = vn.X;
            vecQuat.Y = vn.Y;
            vecQuat.Z = vn.Z;
            vecQuat.W = 0.0f;

            resQuat = vecQuat * conjugate();
            resQuat = this * resQuat;

            return new Vector3(resQuat.X, resQuat.Y, resQuat.Z);
        }
开发者ID:lvarvel,项目名称:aura,代码行数:17,代码来源:Quaternion.cs

示例12: TriangleLight

 public TriangleLight(int tri, TriangleMeshLight meshlight)
 {
     tri3 = 3 * tri;
     this.meshlight = meshlight;
     int a = meshlight.triangles[tri3 + 0];
     int b = meshlight.triangles[tri3 + 1];
     int c = meshlight.triangles[tri3 + 2];
     Point3 v0p = meshlight.getPoint(a);
     Point3 v1p = meshlight.getPoint(b);
     Point3 v2p = meshlight.getPoint(c);
     ng = Point3.normal(v0p, v1p, v2p);
     area = 0.5f * ng.Length();
     ng.normalize();
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:14,代码来源:TriangleMeshLight.cs

示例13: getSamples

            public void getSamples(ShadingState state)
            {
                if (meshlight.numSamples == 0)
                    return;
                Vector3 n = state.getNormal();
                Point3 p = state.getPoint();
                // vector towards each vertex of the light source
                Vector3 p0 = Point3.sub(meshlight.getPoint(meshlight.triangles[tri3 + 0]), p, new Vector3());
                // cull triangle if it is facing the wrong way
                if (Vector3.dot(p0, ng) >= 0)
                    return;
                Vector3 p1 = Point3.sub(meshlight.getPoint(meshlight.triangles[tri3 + 1]), p, new Vector3());
                Vector3 p2 = Point3.sub(meshlight.getPoint(meshlight.triangles[tri3 + 2]), p, new Vector3());
                // if all three vertices are below the hemisphere, stop
                if (Vector3.dot(p0, n) <= 0 && Vector3.dot(p1, n) <= 0 && Vector3.dot(p2, n) <= 0)
                    return;
                p0.normalize();
                p1.normalize();
                p2.normalize();
                float dot = Vector3.dot(p2, p0);
                Vector3 h = new Vector3();
                h.x = p2.x - dot * p0.x;
                h.y = p2.y - dot * p0.y;
                h.z = p2.z - dot * p0.z;
                float hlen = h.Length();
                if (hlen > 1e-6f)
                    h.div(hlen);
                else
                    return;
                Vector3 n0 = Vector3.cross(p0, p1, new Vector3());
                float len0 = n0.Length();
                if (len0 > 1e-6f)
                    n0.div(len0);
                else
                    return;
                Vector3 n1 = Vector3.cross(p1, p2, new Vector3());
                float len1 = n1.Length();
                if (len1 > 1e-6f)
                    n1.div(len1);
                else
                    return;
                Vector3 n2 = Vector3.cross(p2, p0, new Vector3());
                float len2 = n2.Length();
                if (len2 > 1e-6f)
                    n2.div(len2);
                else
                    return;

                float cosAlpha = MathUtils.clamp(-Vector3.dot(n2, n0), -1.0f, 1.0f);
                float cosBeta = MathUtils.clamp(-Vector3.dot(n0, n1), -1.0f, 1.0f);
                float cosGamma = MathUtils.clamp(-Vector3.dot(n1, n2), -1.0f, 1.0f);

                float alpha = (float)Math.Acos(cosAlpha);
                float beta = (float)Math.Acos(cosBeta);
                float gamma = (float)Math.Acos(cosGamma);

                float area = alpha + beta + gamma - (float)Math.PI;

                float cosC = MathUtils.clamp(Vector3.dot(p0, p1), -1.0f, 1.0f);
                float salpha = (float)Math.Sin(alpha);
                float product = salpha * cosC;

                // use lower sampling depth for diffuse bounces
                int samples = state.getDiffuseDepth() > 0 ? 1 : meshlight.numSamples;
                Color c = Color.mul(area / samples, meshlight.radiance);
                for (int i = 0; i < samples; i++)
                {
                    // random offset on unit square
                    double randX = state.getRandom(i, 0, samples);
                    double randY = state.getRandom(i, 1, samples);

                    float phi = (float)randX * area - alpha + (float)Math.PI;
                    float sinPhi = (float)Math.Sin(phi);
                    float cosPhi = (float)Math.Cos(phi);

                    float u = cosPhi + cosAlpha;
                    float v = sinPhi - product;

                    float q = (-v + cosAlpha * (cosPhi * -v + sinPhi * u)) / (salpha * (sinPhi * -v - cosPhi * u));
                    float q1 = 1.0f - q * q;
                    if (q1 < 0.0f)
                        q1 = 0.0f;

                    float sqrtq1 = (float)Math.Sqrt(q1);
                    float ncx = q * p0.x + sqrtq1 * h.x;
                    float ncy = q * p0.y + sqrtq1 * h.y;
                    float ncz = q * p0.z + sqrtq1 * h.z;
                    dot = p1.dot(ncx, ncy, ncz);
                    float z = 1.0f - (float)randY * (1.0f - dot);
                    float z1 = 1.0f - z * z;
                    if (z1 < 0.0f)
                        z1 = 0.0f;
                    Vector3 nd = new Vector3();
                    nd.x = ncx - dot * p1.x;
                    nd.y = ncy - dot * p1.y;
                    nd.z = ncz - dot * p1.z;
                    nd.normalize();
                    float sqrtz1 = (float)Math.Sqrt(z1);
                    Vector3 result = new Vector3();
                    result.x = z * p1.x + sqrtz1 * nd.x;
//.........这里部分代码省略.........
开发者ID:rzel,项目名称:sunflowsharp,代码行数:101,代码来源:TriangleMeshLight.cs

示例14: generate

 private TriangleMesh generate(int[] tris, float[] verts, bool smoothNormals)
 {
     ParameterList pl = new ParameterList();
     pl.addIntegerArray("triangles", tris);
     pl.addPoints("points", ParameterList.InterpolationType.VERTEX, verts);
     if (smoothNormals)
     {
         float[] normals = new float[verts.Length]; // filled with 0's
         Point3 p0 = new Point3();
         Point3 p1 = new Point3();
         Point3 p2 = new Point3();
         Vector3 n = new Vector3();
         for (int i3 = 0; i3 < tris.Length; i3 += 3)
         {
             int v0 = tris[i3 + 0];
             int v1 = tris[i3 + 1];
             int v2 = tris[i3 + 2];
             p0.set(verts[3 * v0 + 0], verts[3 * v0 + 1], verts[3 * v0 + 2]);
             p1.set(verts[3 * v1 + 0], verts[3 * v1 + 1], verts[3 * v1 + 2]);
             p2.set(verts[3 * v2 + 0], verts[3 * v2 + 1], verts[3 * v2 + 2]);
             Point3.normal(p0, p1, p2, n); // compute normal
             // add face normal to each vertex
             // note that these are not normalized so this in fact weights
             // each normal by the area of the triangle
             normals[3 * v0 + 0] += n.x;
             normals[3 * v0 + 1] += n.y;
             normals[3 * v0 + 2] += n.z;
             normals[3 * v1 + 0] += n.x;
             normals[3 * v1 + 1] += n.y;
             normals[3 * v1 + 2] += n.z;
             normals[3 * v2 + 0] += n.x;
             normals[3 * v2 + 1] += n.y;
             normals[3 * v2 + 2] += n.z;
         }
         // normalize all the vectors
         for (int i3 = 0; i3 < normals.Length; i3 += 3)
         {
             n.set(normals[i3 + 0], normals[i3 + 1], normals[i3 + 2]);
             n.normalize();
             normals[i3 + 0] = n.x;
             normals[i3 + 1] = n.y;
             normals[i3 + 2] = n.z;
         }
         pl.addVectors("normals", ParameterList.InterpolationType.VERTEX, normals);
     }
     TriangleMesh m = new TriangleMesh();
     if (m.update(pl, null))
         return m;
     // something failed in creating the mesh, the error message will be
     // printed by the mesh itself - no need to repeat it here
     return null;
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:52,代码来源:FileMesh.cs


注:本文中的System.Vector3.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。