Introduce float3 type.
This commit is contained in:
@@ -508,6 +508,26 @@ namespace OpenRA
|
|||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
else if (fieldType == typeof(float3))
|
||||||
|
{
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
float x = 0;
|
||||||
|
float y = 0;
|
||||||
|
float z = 0;
|
||||||
|
float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out x);
|
||||||
|
float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out y);
|
||||||
|
|
||||||
|
// z component is optional for compatibility with older float2 definitions
|
||||||
|
if (parts.Length > 2)
|
||||||
|
float.TryParse(parts[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out z);
|
||||||
|
|
||||||
|
return new float3(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
|
}
|
||||||
else if (fieldType == typeof(Rectangle))
|
else if (fieldType == typeof(Rectangle))
|
||||||
{
|
{
|
||||||
if (value != null)
|
if (value != null)
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ namespace OpenRA
|
|||||||
void SetBool(string name, bool value);
|
void SetBool(string name, bool value);
|
||||||
void SetVec(string name, float x);
|
void SetVec(string name, float x);
|
||||||
void SetVec(string name, float x, float y);
|
void SetVec(string name, float x, float y);
|
||||||
|
void SetVec(string name, float x, float y, float z);
|
||||||
void SetVec(string name, float[] vec, int length);
|
void SetVec(string name, float[] vec, int length);
|
||||||
void SetTexture(string param, ITexture texture);
|
void SetTexture(string param, ITexture texture);
|
||||||
void SetMatrix(string param, float[] mtx);
|
void SetMatrix(string param, float[] mtx);
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
public readonly float X, Y, Z, U, V, P, C;
|
public readonly float X, Y, Z, U, V, P, C;
|
||||||
|
|
||||||
public Vertex(float2 xy, float u, float v, float p, float c)
|
public Vertex(float3 xyz, float u, float v, float p, float c)
|
||||||
: this(xy.X, xy.Y, 0, u, v, p, c) { }
|
: this(xyz.X, xyz.Y, xyz.Z, u, v, p, c) { }
|
||||||
|
|
||||||
public Vertex(float[] xyz, float u, float v, float p, float c)
|
public Vertex(float[] xyz, float u, float v, float p, float c)
|
||||||
: this(xyz[0], xyz[1], xyz[2], u, v, p, c) { }
|
: this(xyz[0], xyz[1], xyz[2], u, v, p, c) { }
|
||||||
|
|||||||
@@ -254,6 +254,7 @@
|
|||||||
<Compile Include="Traits\Player\IndexedPlayerPalette.cs" />
|
<Compile Include="Traits\Player\IndexedPlayerPalette.cs" />
|
||||||
<Compile Include="Traits\ActivityUtils.cs" />
|
<Compile Include="Traits\ActivityUtils.cs" />
|
||||||
<Compile Include="FileSystem\ZipFolder.cs" />
|
<Compile Include="FileSystem\ZipFolder.cs" />
|
||||||
|
<Compile Include="Primitives\float3.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="FileSystem\D2kSoundResources.cs" />
|
<Compile Include="FileSystem\D2kSoundResources.cs" />
|
||||||
|
|||||||
54
OpenRA.Game/Primitives/float3.cs
Normal file
54
OpenRA.Game/Primitives/float3.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace OpenRA
|
||||||
|
{
|
||||||
|
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct float3
|
||||||
|
{
|
||||||
|
public readonly float X, Y, Z;
|
||||||
|
public float2 XY { get { return new float2(X, Y); } }
|
||||||
|
|
||||||
|
public float3(float x, float y, float z) { X = x; Y = y; Z = z; }
|
||||||
|
public float3(float2 xy, float z) { X = xy.X; Y = xy.Y; Z = z; }
|
||||||
|
|
||||||
|
public static implicit operator float3(int2 src) { return new float3(src.X, src.Y, 0); }
|
||||||
|
public static implicit operator float3(float2 src) { return new float3(src.X, src.Y, 0); }
|
||||||
|
|
||||||
|
public static float3 operator +(float3 a, float3 b) { return new float3(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
|
||||||
|
public static float3 operator -(float3 a, float3 b) { return new float3(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
|
||||||
|
public static float3 operator -(float3 a) { return new float3(-a.X, -a.Y, -a.Z); }
|
||||||
|
public static float3 operator *(float3 a, float3 b) { return new float3(a.X * b.X, a.Y * b.Y, a.Z * b.Z); }
|
||||||
|
public static float3 operator *(float a, float3 b) { return new float3(a * b.X, a * b.Y, a * b.Z); }
|
||||||
|
public static float3 operator /(float3 a, float3 b) { return new float3(a.X / b.X, a.Y / b.Y, a.Z / b.Z); }
|
||||||
|
public static float3 operator /(float3 a, float b) { return new float3(a.X / b, a.Y / b, a.Z / b); }
|
||||||
|
|
||||||
|
public static bool operator ==(float3 me, float3 other) { return me.X == other.X && me.Y == other.Y && me.Z == other.Z; }
|
||||||
|
public static bool operator !=(float3 me, float3 other) { return !(me == other); }
|
||||||
|
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
var o = obj as float3?;
|
||||||
|
return o != null && o == this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() { return "{0},{1},{2}".F(X, Y, Z); }
|
||||||
|
|
||||||
|
public static readonly float3 Zero = new float3(0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -215,6 +215,9 @@ namespace OpenRA.Platforms.Default
|
|||||||
public delegate void Uniform2f(int location, float v0, float v1);
|
public delegate void Uniform2f(int location, float v0, float v1);
|
||||||
public static Uniform2f glUniform2f { get; private set; }
|
public static Uniform2f glUniform2f { get; private set; }
|
||||||
|
|
||||||
|
public delegate void Uniform3f(int location, float v0, float v1, float v2);
|
||||||
|
public static Uniform3f glUniform3f { get; private set; }
|
||||||
|
|
||||||
public delegate void Uniform1fv(int location, int count, IntPtr value);
|
public delegate void Uniform1fv(int location, int count, IntPtr value);
|
||||||
public static Uniform1fv glUniform1fv { get; private set; }
|
public static Uniform1fv glUniform1fv { get; private set; }
|
||||||
|
|
||||||
@@ -395,6 +398,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
glUniform1i = Bind<Uniform1i>("glUniform1i");
|
glUniform1i = Bind<Uniform1i>("glUniform1i");
|
||||||
glUniform1f = Bind<Uniform1f>("glUniform1f");
|
glUniform1f = Bind<Uniform1f>("glUniform1f");
|
||||||
glUniform2f = Bind<Uniform2f>("glUniform2f");
|
glUniform2f = Bind<Uniform2f>("glUniform2f");
|
||||||
|
glUniform3f = Bind<Uniform3f>("glUniform3f");
|
||||||
glUniform1fv = Bind<Uniform1fv>("glUniform1fv");
|
glUniform1fv = Bind<Uniform1fv>("glUniform1fv");
|
||||||
glUniform2fv = Bind<Uniform2fv>("glUniform2fv");
|
glUniform2fv = Bind<Uniform2fv>("glUniform2fv");
|
||||||
glUniform3fv = Bind<Uniform3fv>("glUniform3fv");
|
glUniform3fv = Bind<Uniform3fv>("glUniform3fv");
|
||||||
|
|||||||
@@ -189,6 +189,17 @@ namespace OpenRA.Platforms.Default
|
|||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetVec(string name, float x, float y, float z)
|
||||||
|
{
|
||||||
|
VerifyThreadAffinity();
|
||||||
|
OpenGL.glUseProgram(program);
|
||||||
|
OpenGL.CheckGLError();
|
||||||
|
var param = OpenGL.glGetUniformLocation(program, name);
|
||||||
|
OpenGL.CheckGLError();
|
||||||
|
OpenGL.glUniform3f(param, x, y, z);
|
||||||
|
OpenGL.CheckGLError();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetVec(string name, float[] vec, int length)
|
public void SetVec(string name, float[] vec, int length)
|
||||||
{
|
{
|
||||||
VerifyThreadAffinity();
|
VerifyThreadAffinity();
|
||||||
|
|||||||
Reference in New Issue
Block a user