本文整理汇总了C#中Vector4.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector4.Normalize方法的具体用法?C# Vector4.Normalize怎么用?C# Vector4.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector4
的用法示例。
在下文中一共展示了Vector4.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePoints
private void CreatePoints()
{
var lines = dataSet.text.Split('\n');
points = new Particle[lines.Length - 2];//lines.Length - 1];
data = new Quaternion[lines.Length - 2];//lines.Length - 1];
for (int i = 1; i < lines.Length - 1; ++i)
{
var line = lines[i].Split(' ');
var normal = new Vector4(float.Parse(line[2]), float.Parse(line[3]), float.Parse(line[4]), float.Parse(line[5]));
normal.Normalize();
data[i - 1] = new Quaternion(normal.x, normal.y, normal.z, normal.w);
var particle = new Particle()
{
position = StereographicProjection(normal),
size = ParticleSize,//Mathf.Abs(ParticleSize * float.Parse(line[2])),
color = Color.white
};
points[i - 1] = particle;
}
ps.SetParticles(points, points.Length);
}
示例2: Update
new void Update()
{
ncol = new Vector4(col.x, col.y, col.z, col.w);
if(mi.mode == MainInterface.Mode.Delete){
//Debug.Log("Red mode");
ncol = new Vector4(1, col.y/8, col.z/8, col.w);
}
else{
if(ncol.x > ncol.y && ncol.x > ncol.z){
RValue = ncol.x;
GValue = (ncol.x - ncol.y)*(2f/3f) + ncol.y;
BValue = (ncol.x - ncol.z)*(2f/3f) + ncol.z;
}
else if(ncol.y > ncol.x && ncol.y > ncol.z){
RValue = (ncol.y - ncol.x)*(2f/3f) + ncol.x;
GValue = ncol.y;
BValue = (ncol.y - ncol.z)*(2f/3f) + ncol.z;
}
else if(ncol.z > ncol.x && ncol.z > ncol.y){
RValue = (ncol.z - ncol.x)*(2f/3f) + ncol.x;
GValue = (ncol.z - ncol.y)*(2f/3f) + ncol.y;
BValue = ncol.z;
}
//Multiply modifier with Raw marker colour
//ncol.x *= yellowR;
//ncol.y *= yellowG;
//ncol.z *= yellowB;
//Multiply by itself to emphasize tint
//float colX = Mathf.Pow(ncol.x, 1.5f);
//float colY = Mathf.Pow(ncol.y, 1.5f);
//float colZ = Mathf.Pow(ncol.z, 1.5f);
//ncol = new Vector4(colX, colY, colZ, 1f);
ncol = new Vector4(RValue, GValue, BValue, 1f);
ncol.Normalize();
//To account for darkening by normalization
ncol *= 1.7f;
//Debug.Log ("Normalize Col: " + col);
}
Shader.SetGlobalColor("_MarkerHue", ncol);
//Debug.Log("Jman Update");
if (on){
//Debug.Log ("On is On");
base.Update();
}
}
示例3: CalculeImage
public void CalculeImage(Vector3 startPoint, out Vector3 imagePoint, out Vector3 normal, out Vector4 tangentX)
{
imagePoint = startPoint;
Vector3 slopes = new Vector3();
Vector3 vecteur = new Vector3();
Vector3 oneNormal = new Vector3();
Vector3 oneSlope = new Vector3();
foreach (Vague vague in vagues)
{
if (vague.gameObject.activeInHierarchy)
{
vague.CalculeVecteur(startPoint, out vecteur, out oneNormal, amount);
imagePoint += vecteur;
oneSlope.x = -oneNormal.x / oneNormal.y;
oneSlope.y = 0.0f;
oneSlope.z = -oneNormal.z / oneNormal.y;
slopes += oneSlope;
}
}
//TODO : calculer la normale ou la pente des perlinVagues
//foreach (PerlinVague perlinVague in perlinVagues) {
// if (perlinVague.gameObject.activeInHierarchy) {
// imagePoint.y = imagePoint.y + perlinVague.CalculeHauteur(startPoint,amount);
// }
//}
normal.x = -slopes.x;
normal.y = 1.0f;
normal.z = -slopes.z;
normal.Normalize();
//tangentX.x = 1.0f;
//tangentX.y = slopes.z+slopes.x;
//tangentX.z = 1.0f;
tangentX.x = 1.0f;
tangentX.y = slopes.x;
tangentX.z = 0.0f;
tangentX.w = 1.0f;
tangentX.Normalize();
}
示例4: CreatePoints
public void CreatePoints(string filePath)
{
_infoText.text = "Hit Me 1";
_dataPlot = LoadJson.Instance.LoadFromFile(filePath);
_particles = new Particle[_dataPlot.Particles.Length];
for (int index = 0; index < _dataPlot.Particles.Length; index++)
{
var p = _dataPlot.Particles[index];
var normal = new Vector4(p.Position.x, p.Position.y, p.Position.z, p.Position.w);
normal.Normalize();
_particles[index] = new Particle()
{
position = normal.StereographicProjection(),
color = p.Color,
size = p.Size
};
}
_particleSystem.SetParticles(_particles, _particles.Length);
}
示例5: Start
public void Start()
{
_dataPlot = LoadJson.Instance.Load(_jsonData.text);
_particles = new Particle[_dataPlot.Particles.Length];
_particleSystem = GetComponent<ParticleSystem>();
_camT = Camera.main.transform;
_baseRotation = Quaternion.identity;
_rotations = new[] {Quaternion.identity, Quaternion.identity};
_inV = Vector3.zero;
_sizeSlider.value = ParticleSize;
//Create Points
for (int index = 0; index < _dataPlot.Particles.Length; index++)
{
var p = _dataPlot.Particles[index];
var normal = new Vector4(p.Position.x, p.Position.y, p.Position.z, p.Position.w);
normal.Normalize();
_particles[index] = new Particle()
{
position = normal.StereographicProjection(),
color = p.Color,
size = p.Size
};
}
_particleSystem.SetParticles(_particles, _particles.Length);
//SelectFile.Instance.FileSelected += CreatePoints;
_xPos.text = "0";
_yPos.text = "0";
_zPos.text = "0";
}
示例6: GetTo2DMatrix
/// <summary>
/// Get a matrix which can transform points to 2D
/// </summary>
/// <returns>matrix which can transform points to 2D</returns>
public Matrix4 GetTo2DMatrix()
{
Line trussLocation = (m_truss.Location as LocationCurve).Curve as Line;
startLocation = trussLocation.get_EndPoint(0);
endLocation = trussLocation.get_EndPoint(1);
//use baseline of truss as the X axis
XYZ diff = endLocation - startLocation;
Vector4 xAxis = new Vector4(new Autodesk.Revit.DB.XYZ(diff.X, diff.Y, diff.Z));
xAxis.Normalize();
//get Z Axis
Vector4 zAxis = Vector4.CrossProduct(xAxis, new Vector4(new Autodesk.Revit.DB.XYZ (0, 0, 1)));
zAxis.Normalize();
//get Y Axis, downward
Vector4 yAxis = Vector4.CrossProduct(xAxis, zAxis);
yAxis.Normalize();
//get original point, first point
m_origin = new Vector4(m_points[0]);
return new Matrix4(xAxis, yAxis, zAxis, m_origin);
}
示例7: Normalize
public void Normalize()
{
var vector1 = new Vector4(1, 2, 3, 4);
vector1.Normalize();
var expected = new Vector4(0.1825742f,0.3651484f,0.5477225f,0.7302967f);
Assert.That(expected, Is.EqualTo(vector1).Using(Vector4Comparer.Epsilon));
var vector2 = new Vector4(1, 2, 3, 4);
var result = Vector4.Normalize(vector2);
Assert.That(expected, Is.EqualTo(result).Using(Vector4Comparer.Epsilon));
}
示例8: NormalizeInstance
public static void NormalizeInstance (int times)
{
var value = new Vector4 (0.1f, -2f, -0.2f, 0.56f);
for (int i = 0; i < times; i++) {
value.Normalize ();
}
}
示例9: GetTo2DMatrix
/// <summary>
/// Get a matrix which can transform points to 2D
/// </summary>
/// <returns>matrix which can transform points to 2D</returns>
public override Matrix4 GetTo2DMatrix()
{
//get the location curve
LocationCurve location = m_data.Location as LocationCurve;
Vector4 xAxis = new Vector4(1, 0, 0);
Vector4 yAxis = new Vector4(0, 1, 0);
Vector4 zAxis = new Vector4(0, 0, 1);
Vector4 origin = new Vector4(0, 0, 0);
if (location != null)
{
Curve curve = location.Curve;
if (!(curve is Autodesk.Revit.DB.Line))
{
throw new Exception("Opening cannot build on this Wall");
}
Autodesk.Revit.DB.XYZ start = curve.get_EndPoint(0);
Autodesk.Revit.DB.XYZ end = curve.get_EndPoint(1);
xAxis = new Vector4((float)(end.X - start.X),
(float)(end.Y - start.Y), (float)(end.Z - start.Z));
xAxis.Normalize();
//because in the windows UI, Y axis is downward
yAxis = new Vector4(0, 0, -1);
zAxis = Vector4.CrossProduct(xAxis, yAxis);
zAxis.Normalize();
origin = new Vector4((float)(end.X + start.X) / 2,
(float)(end.Y + start.Y) / 2, (float)(end.Z + start.Z) / 2);
}
return new Matrix4(xAxis, yAxis, zAxis, origin);
}
示例10: GetTo2DMatrix
/// <summary>
/// Get a matrix which can transform points to 2D
/// </summary>
/// <returns>
/// matrix which can transform points to 2D
/// </returns>
private Matrix4 GetTo2DMatrix()
{
Autodesk.Revit.DB.XYZ startXYZ = m_myDocument.WallGeometry.StartXYZ;
Autodesk.Revit.DB.XYZ endXYZ = m_myDocument.WallGeometry.EndXYZ;
XYZ sub = endXYZ - startXYZ;
Vector4 xAxis = new Vector4(new Autodesk.Revit.DB.XYZ(sub.X, sub.Y, sub.Z));
xAxis.Normalize();
//because in the windows UI, Y axis is downward
Vector4 yAxis = new Vector4(new Autodesk.Revit.DB.XYZ(0, 0, -1));
yAxis.Normalize();
Vector4 zAxis = Vector4.CrossProduct(xAxis, yAxis);
zAxis.Normalize();
Vector4 origin = new Vector4(m_drawing.Geometry.GridVertexesXYZ[0]);
return new Matrix4(xAxis, yAxis, zAxis, origin);
}
示例11: _CreateTangentSpace
void _CreateTangentSpace(out Vector4 normal, out Vector4 tangent, out Vector4 binormal)
{
Vector3 point0 = new Vector3(-1.0f, -1.0f, 0.0f);
Vector3 point1 = new Vector3(1.0f, -1.0f, 0.0f);
Vector3 point2 = new Vector3(1.0f, 1.0f, 0.0f);
Vector3 point3 = new Vector3(-1.0f, 1.0f, 0.0f);
Vector3 v3n = Vector3.Cross(point1 - point0, point2 - point0);
normal = new Vector4(v3n.X, v3n.Y, v3n.Z, 0.0f);
if (normal.LengthSquared() > 0.0001f)
normal.Normalize();
Vector3 v3tangent = point1 - point0;
tangent = new Vector4(v3tangent.X, v3tangent.Y, v3tangent.Z, 0.0f);
if (tangent.LengthSquared() > 0.0001f)
tangent.Normalize();
Vector3 v3binormal = point3 - point0;
binormal = new Vector4(v3binormal.X, v3binormal.Y, v3binormal.Z, 0.0f);
if (binormal.LengthSquared() > 0.0001f)
binormal.Normalize();
}
示例12: Update
void Update()
{
// Find the mods
if ( !modffd )
{
modffd = GetComponent<MegaFFD3x3x3>();
modobj = GetComponent<MegaModifyObject>();
}
if ( modffd )
{
Vector3 toolPosition = tool.transform.position;
size = modffd.GridSize();
int gridSize = size*size*size;
distance = new float[gridSize];
entries = new int[gridSize];
indicies = new Vector3[gridSize];
if(inCollision){
for ( int i = 0; i < size; i++ ) // TODO: dim for all ffd
{
for ( int j = 0; j < size; j++ )
{
for ( int k = 0; k < size; k++ )
{
int c = modffd.GridIndex(i, j, k);
indicies[c] = new Vector3 (i,j,k); //indicies of the handle i,j,k
entries[c]=c;
distance[c] = Vector3.Distance(transform.TransformPoint(modffd.GetPoint(i,j,k)),collisionPoint);//There should be collision point instead of pposition of the tool
}
}
}
System.Array.Sort(distance, entries);
if(sphereSwitch){
if(!redSphere){
redSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
redSphere.GetComponent<Renderer>().material.color = Color.red;
redSphere.transform.localScale = new Vector3(0.2f, 0.2f,0.2f);
redSphere.name = "Red Sphere";
}
if(!blueSphere){
blueSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
blueSphere.GetComponent<Renderer>().material.color = Color.blue;
blueSphere.transform.localScale = new Vector3(0.2f, 0.2f,0.2f);
blueSphere.name = "Blue Sphere";
}
if(!greenSphere){
greenSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
greenSphere.GetComponent<Renderer>().material.color = Color.green;
greenSphere.transform.localScale = new Vector3(0.2f, 0.2f,0.2f);
greenSphere.name = "Green Sphere";
}
if(!yellowSphere){
yellowSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
yellowSphere.GetComponent<Renderer>().material.color = Color.yellow;
yellowSphere.transform.localScale = new Vector3(0.2f, 0.2f,0.2f);
yellowSphere.name = "Yellow Sphere";
}
redSphere.transform.position = modffd.GetPoint(entries[0]);
blueSphere.transform.position = modffd.GetPoint(entries[1]);
greenSphere.transform.position = modffd.GetPoint(entries[2]);
yellowSphere.transform.position = modffd.GetPoint(entries[3]);
}
else{
Destroy(redSphere);
Destroy(blueSphere);
Destroy(greenSphere);
Destroy(yellowSphere);
}
Vector4 neighbors = new Vector4(distance[0],distance[1],distance[2],distance[3]);
neighbors.Normalize();
for(int i = 0; i < 4; i++){
if(neighbors[i]==0){
neighbors[i]=0.01f;
}
neighbors[i] = 1 / neighbors[i];
}
neighbors.Normalize();
currentPosition = tool.transform.position;
displacement = currentPosition-previousPosition;
Debug.Log("Displacement: " +displacement);
if(!firsttimecollision)
{
// positionoffirstcollisionpoint += displacement;
//
// if(displacement.y < 0 && (positionoffirstcollisionpoint.y < firstcollisionpoint.y) )
// {
//.........这里部分代码省略.........
示例13: WallMatrix
/// <summary>
/// Wall matrix
/// </summary>
/// <returns></returns>
public Matrix4 WallMatrix()
{
//get the location curve
LocationCurve location = m_dataProfile.Location as LocationCurve;
Vector4 xAxis = new Vector4(1,0,0);
Vector4 yAxis = new Vector4(0, 1, 0);
Vector4 zAxis = new Vector4(0, 0, 1);
Vector4 origin = new Vector4(0, 0, 0);
if(location != null)
{
Curve curve = location.Curve;
Autodesk.Revit.DB.XYZ start = curve.get_EndPoint(0);
Autodesk.Revit.DB.XYZ end = curve.get_EndPoint(1);
xAxis = new Vector4((float)(end.X - start.X),
(float)(end.Y - start.Y), (float)(end.Z- start.Z));
xAxis.Normalize();
yAxis = new Vector4(0 ,0, 1);
zAxis = Vector4.CrossProduct(xAxis, yAxis);
zAxis.Normalize();
origin = new Vector4((float)(end.X + start.X) / 2,
(float)(end.Y + start.Y) / 2, (float)(end.Z + start.Z) / 2);
}
return new Matrix4(xAxis, yAxis, zAxis, origin);
}
示例14: TerrainModel
public TerrainModel(GraphicsDevice device,
int terrainSize, int terrainSegments, float terrainStart,
int xOffset, int zOffset, Vector3 terrainScale,
float[,] heightMap, float[,] roadMap,
Effect effect, DirectionalLight directionalLight)
{
this.device = device;
int terrainSizeMinusOne = terrainSize;
terrainSize++;
int vertexCount = terrainSize * terrainSize;
vertices = new MultitexturedVertex[vertexCount];
for (int z = 0; z < terrainSize; z++)
{
for (int x = 0; x < terrainSize; x++)
{
var textureWeights = new Vector4(
roadMap[xOffset + x, zOffset + z],
MathHelper.Clamp(1 - Math.Abs(heightMap[xOffset + x, zOffset + z] - 0.2f) / 0.4f, 0, 1),
MathHelper.Clamp(1 - Math.Abs(heightMap[xOffset + x, zOffset + z] - 0.7f) / 0.2f, 0, 1),
MathHelper.Clamp(1 - Math.Abs(heightMap[xOffset + x, zOffset + z] - 1) / 0.3f, 0, 1)
);
textureWeights.Normalize();
vertices[z * terrainSize + x] = new MultitexturedVertex(
terrainScale * new Vector3(
(terrainStart + xOffset + x), // X
heightMap[xOffset + x, zOffset + z], // Y
(terrainStart + zOffset + z)), // Z
Vector3.Zero, // Normal
Vector3.Zero, // Binormal
Vector3.Zero, // Tangent
new Vector2(x / 8f, z / 8f),
textureWeights);
}
}
BoundingBox = BoundingBox.CreateFromPoints(vertices.Select(vert => vert.Position));
//MinBox = BoundingBox.CreateFromPoints(new Vector3[] { BoundingBox.Min.GetXZProjection(false), BoundingBox.Max.GetXZProjection(false) });
#region Indicies & Vertex normals setup
int flexIndice = 1;
int rowIndex = 2;
int[] indices = new int[terrainSizeMinusOne * terrainSizeMinusOne * 6];
indices[0] = 0;
indices[1] = terrainSize;
indices[2] = flexIndice;
for (int i = 5; i <= indices.Length; i += 3)
{
indices[i - 2] = indices[i - 4];
indices[i - 1] = indices[i - 3];
if (i % 2 == 0)
{
flexIndice -= terrainSizeMinusOne;
indices[i] = flexIndice;
}
else
{
flexIndice += terrainSize;
indices[i] = flexIndice;
}
if (i + 3 >= indices.Length)
break;
else if (rowIndex * terrainSize - 1 == indices[i])
{
indices[i + 1] = flexIndice - terrainSize + 1;
indices[i + 2] = flexIndice + 1;
indices[i + 3] = flexIndice - terrainSize + 2;
flexIndice = indices[i + 3];
rowIndex++;
i += 3;
}
}
for (int i = 0; i < indices.Length / 3; i++)
{
Vector3 firstvec = vertices[indices[i * 3]].Position;
Vector3 secondvec = vertices[indices[i * 3 + 1]].Position;
Vector3 thirdvec = vertices[indices[i * 3 + 2]].Position;
Vector3 firstsub = secondvec - firstvec;
Vector3 secondsub = thirdvec - firstvec;
Vector3 normal;
if(i % 2 == 0)
{
normal = Vector3.Cross(firstsub, secondsub);
}else{
normal = Vector3.Cross(secondsub, firstsub);
}
normal.Normalize();
vertices[indices[i * 3]].Normal += normal;
//.........这里部分代码省略.........
示例15: GetTo2DMatrix
/// <summary>
/// Get a matrix which can transform points to 2D
/// </summary>
/// <returns>matrix which can transform points to 2D</returns>
public override Matrix4 GetTo2DMatrix()
{
//get transform used to transform points to plane whose normal is Zaxis of beam
Vector4 xAxis = new Vector4(m_data.HandOrientation);
xAxis.Normalize();
//Because Y axis in windows UI is downward, so we should Multiply(-1) here
Vector4 yAxis = new Vector4(m_data.FacingOrientation.Multiply(-1));
yAxis.Normalize();
Vector4 zAxis = yAxis.CrossProduct(xAxis);
zAxis.Normalize();
Vector4 vOrigin = new Vector4(m_points[0][0]);
Matrix4 result = new Matrix4(xAxis, yAxis, zAxis, vOrigin);
m_MatrixZaxis = result;
//get transform used to transform points to plane whose normal is Yaxis of beam
xAxis = new Vector4(m_data.HandOrientation);
xAxis.Normalize();
zAxis = new Vector4(m_data.FacingOrientation);
zAxis.Normalize();
yAxis = (xAxis.CrossProduct(zAxis)) * (-1);
yAxis.Normalize();
result = new Matrix4(xAxis, yAxis, zAxis, vOrigin);
m_MatrixYaxis = result;
return m_MatrixZaxis;
}