- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
首先,请原谅我的英语,我是法国人...我写了一个不起作用的代码。我想画一个像 Minecraft 一样的 mutliples block ,但是在 Voxel 中。在我的 map 的一侧,结果很好:
但另一方面,我明白了:
But in this side of my map, it's no good :(
一些面孔通过另一些面孔出现...谁有主意?我的法线?
我的函数 Remake() 没有使用,它用于删除面...
namespace LandOfCube.Models
{
class Block
{
VertexBuffer instanceBuffer;
public enum Form
{
all,
noUp,
noDown,
noRight,
noLeft,
noFront,
noBack
}
public Form cubeForm = Form.all;
GraphicsDevice Graphics;
Effect shader;
private VertexBuffer vb;
Color CubeColor;
public Vector3 pos;
VertexPositionColorNormal[] vertices;
VertexPositionColorNormal[] verticesNoUp;
VertexPositionColorNormal[] verticesNoDown;
VertexPositionColorNormal[] verticesNoFront;
VertexPositionColorNormal[] verticesNoBack;
VertexPositionColorNormal[] verticesNoRight;
VertexPositionColorNormal[] verticesNoLeft;
private VertexPositionColorNormal[] Front = new VertexPositionColorNormal[5];
private VertexPositionColorNormal[] Back = new VertexPositionColorNormal[5];
private VertexPositionColorNormal[] Right = new VertexPositionColorNormal[5];
private VertexPositionColorNormal[] Up = new VertexPositionColorNormal[5];
private VertexPositionColorNormal[] Left = new VertexPositionColorNormal[5];
private VertexPositionColorNormal[] Down = new VertexPositionColorNormal[5];
public Vector3 normalFront = Vector3.Forward;
public Vector3 normalBack = Vector3.Backward;
public Vector3 normalTop = Vector3.Up;
public Vector3 normalBottom = Vector3.Down;
public Vector3 normalLeft = Vector3.Left;
public Vector3 normalRight = Vector3.Right;
public Block(GraphicsDevice graph, Color color, Vector3 position, ContentManager content)
{
Graphics = graph;
shader = content.Load<Effect>("effects");
CubeColor = color;
pos = position;
Init();
SetVertices();
}
bool test = false;
public void Draw(Camera camera)
{
Graphics.SetVertexBuffer(vb);
shader.CurrentTechnique = shader.Techniques["Colored"];
shader.Parameters["xView"].SetValue(camera.View);
shader.Parameters["xProjection"].SetValue(camera.Projection);
shader.Parameters["xWorld"].SetValue(Matrix.Identity);
Vector3 lightDirection = new Vector3(1.0f, -1.0f, -1.0f);
lightDirection.Normalize();
shader.Parameters["xLightDirection"].SetValue(lightDirection);
shader.Parameters["xAmbient"].SetValue(0.1f);
shader.Parameters["xEnableLighting"].SetValue(true);
foreach (EffectPass pass in shader.CurrentTechnique.Passes)
{
pass.Apply();
this.Graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, vertices.Length / 3);
}
}
#region Methode abstraites
private void Init()
{
InitFront();
InitBack();
InitDown();
InitUp();
InitLeft();
InitRight();
}
public void Remake()
{
switch (cubeForm)
{
case Form.noBack:
vertices = verticesNoBack;
break;
case Form.noFront:
vertices = verticesNoFront;
break;
case Form.noUp:
vertices = verticesNoUp;
break;
case Form.noDown:
vertices = verticesNoDown;
break;
case Form.noRight:
vertices = verticesNoRight;
break;
case Form.noLeft:
vertices = verticesNoLeft;
break;
}
vb = new VertexBuffer(Graphics, typeof(VertexPositionColorNormal), vertices.Length, BufferUsage.None);
vb.SetData(vertices);
verticesNoBack = null;
verticesNoDown = null;
verticesNoFront = null;
verticesNoLeft = null;
verticesNoRight = null;
verticesNoUp = null;
test = true;
}
public void SetVertices()
{
this.vertices = new VertexPositionColorNormal[36];
int y = 0;
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Up[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Down[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Front[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Back[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Right[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Left[x]; y++;
}
setNoBack();
setNoFront();
setNoUp();
setNoDown();
setNoRight();
setNoLeft();
vb = new VertexBuffer(Graphics, typeof(VertexPositionColorNormal), vertices.Length, BufferUsage.None);
vb.SetData(vertices);
Clean();
}
#region InitFaces
public void setNoBack()
{
this.verticesNoBack = new VertexPositionColorNormal[30];
int y = 0;
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Up[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Down[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Front[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Right[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Left[x]; y++;
}
}
public void setNoFront()
{
this.verticesNoFront = new VertexPositionColorNormal[30];
int y = 0;
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Up[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Down[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Back[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Right[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Left[x]; y++;
}
}
public void setNoUp()
{
this.verticesNoUp = new VertexPositionColorNormal[30];
int y = 0;
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Front[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Down[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Back[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Right[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Left[x]; y++;
}
}
public void setNoDown()
{
this.verticesNoFront = new VertexPositionColorNormal[30];
int y = 0;
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Up[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Front[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Back[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Right[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Left[x]; y++;
}
}
public void setNoLeft()
{
this.verticesNoLeft = new VertexPositionColorNormal[30];
int y = 0;
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Up[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Down[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Back[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Right[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Front[x]; y++;
}
}
public void setNoRight()
{
this.verticesNoRight = new VertexPositionColorNormal[30];
int y = 0;
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Up[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Down[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Back[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Front[x]; y++;
}
for (int x = 0; x < 6; x++)
{
this.vertices[y] = Left[x]; y++;
}
}
public void InitFront()
{
this.Front = new VertexPositionColorNormal[6];
Front[0].Position = new Vector3(pos.X, pos.Y + 1, pos.Z);
Front[0].Color = Color.Blue;
Front[0].Normal = normalFront;
Front[1].Position = new Vector3(pos.X, pos.Y, pos.Z + 1);
Front[1].Color = Color.Blue;
Front[1].Normal = normalFront;
Front[2].Position = new Vector3(pos.X, pos.Y, pos.Z);
Front[2].Color = Color.Blue;
Front[2].Normal = normalFront;
Front[3].Position = new Vector3(pos.X, pos.Y + 1, pos.Z);
Front[3].Color = Color.Blue;
Front[3].Normal = normalFront;
Front[4].Position = new Vector3(pos.X, pos.Y + 1, pos.Z + 1);
Front[4].Color = Color.Blue;
Front[4].Normal = normalFront;
Front[5].Position = new Vector3(pos.X, pos.Y, pos.Z + 1);
Front[5].Color = Color.Blue;
Front[5].Normal = normalFront;
}
public void InitBack()
{
this.Back = new VertexPositionColorNormal[6];
Back[0].Position = new Vector3(pos.X + 1, pos.Y, pos.Z + 1);
Back[0].Color = Color.Red;
Back[0].Normal = normalBack;
Back[1].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z);
Back[1].Color = Color.Red;
Back[1].Normal = normalBack;
Back[2].Position = new Vector3(pos.X + 1, pos.Y, pos.Z);
Back[2].Color = Color.Red;
Back[2].Normal = normalBack;
Back[3].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z + 1);
Back[3].Color = Color.Red;
Back[3].Normal = normalBack;
Back[4].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z);
Back[4].Color = Color.Red;
Back[4].Normal = normalBack;
Back[5].Position = new Vector3(pos.X + 1, pos.Y, pos.Z + 1);
Back[5].Color = Color.Red;
Back[5].Normal = normalBack;
}
public void InitUp()
{
this.Up = new VertexPositionColorNormal[6];
Up[0].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z);
Up[0].Color = Color.Black;
Up[0].Normal = normalTop;
Up[1].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z + 1);
Up[1].Color = Color.Black;
Up[1].Normal = normalTop;
Up[2].Position = new Vector3(pos.X, pos.Y + 1, pos.Z + 1);
Up[2].Color = Color.Black;
Up[2].Normal = normalTop;
Up[3].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z);
Up[3].Color = Color.Black;
Up[3].Normal = normalTop;
Up[4].Position = new Vector3(pos.X, pos.Y + 1, pos.Z + 1);
Up[4].Color = Color.Black;
Up[4].Normal = normalTop;
Up[5].Position = new Vector3(pos.X, pos.Y + 1, pos.Z);
Up[5].Color = Color.Black;
Up[5].Normal = normalTop;
}
public void InitDown()
{
this.Down = new VertexPositionColorNormal[6];
Down[0].Position = new Vector3(pos.X + 1, pos.Y, pos.Z);
Down[0].Color = Color.Orange;
Down[0].Normal = normalBottom;
Down[1].Position = new Vector3(pos.X, pos.Y, pos.Z);
Down[1].Color = Color.Orange;
Down[1].Normal = normalBottom;
Down[2].Position = new Vector3(pos.X, pos.Y, pos.Z + 1);
Down[2].Color = Color.Orange;
Down[2].Normal = normalBottom;
Down[3].Position = new Vector3(pos.X + 1, pos.Y, pos.Z);
Down[3].Color = Color.Orange;
Down[3].Normal = normalBottom;
Down[4].Position = new Vector3(pos.X, pos.Y, pos.Z + 1);
Down[4].Color = Color.Orange;
Down[4].Normal = normalBottom;
Down[5].Position = new Vector3(pos.X + 1, pos.Y, pos.Z + 1);
Down[5].Color = Color.Orange;
Down[5].Normal = normalBottom;
}
public void InitRight()
{
this.Right = new VertexPositionColorNormal[6];
Right[0].Position = new Vector3(pos.X + 1, pos.Y, pos.Z + 1);
Right[0].Color = Color.Green;
Right[0].Normal = normalRight;
Right[1].Position = new Vector3(pos.X, pos.Y, pos.Z + 1);
Right[1].Color = Color.Green;
Right[1].Normal = normalRight;
Right[2].Position = new Vector3(pos.X, pos.Y + 1, pos.Z + 1);
Right[2].Color = Color.Green;
Right[3].Normal = normalRight;
Right[3].Position = new Vector3(pos.X + 1, pos.Y, pos.Z + 1);
Right[3].Color = Color.Green;
Right[3].Normal = normalRight;
Right[4].Position = new Vector3(pos.X, pos.Y + 1, pos.Z + 1);
Right[4].Color = Color.Green;
Right[4].Normal = normalRight;
Right[5].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z + 1);
Right[5].Color = Color.Green;
Right[5].Normal = normalRight;
}
public void InitLeft()
{
this.Left = new VertexPositionColorNormal[6];
Left[0].Position = new Vector3(pos.X, pos.Y, pos.Z);
Left[0].Color = Color.Aqua;
Left[0].Normal = normalLeft;
Left[1].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z);
Left[1].Color = Color.Aqua;
Left[1].Normal = normalLeft;
Left[2].Position = new Vector3(pos.X, pos.Y + 1, pos.Z);
Left[2].Color = Color.Aqua;
Left[2].Normal = normalLeft;
Left[3].Position = new Vector3(pos.X, pos.Y, pos.Z);
Left[3].Color = Color.Aqua;
Left[3].Normal = normalLeft;
Left[4].Position = new Vector3(pos.X + 1, pos.Y, pos.Z);
Left[4].Color = Color.Aqua;
Left[4].Normal = normalLeft;
Left[5].Position = new Vector3(pos.X + 1, pos.Y + 1, pos.Z);
Left[5].Color = Color.Aqua;
Left[5].Normal = normalLeft;
}
#endregion
private void setTriangleNormal(VertexPositionColorNormal v1, VertexPositionColorNormal v2, VertexPositionColorNormal v3)
{
Vector3 side1 = v1.Position - v3.Position;
Vector3 side2 = v1.Position - v2.Position;
Vector3 normal = Vector3.Cross(side1, side2);
v1.Normal += normal;
v2.Normal += normal;
v3.Normal += normal;
v1.Position.Normalize();
v1.Position.Normalize();
v1.Position.Normalize();
}
public void Clean()
{
Front = null;
Back = null;
Right = null;
Left = null;
Up = null;
Down = null;
}
#endregion
}
}
最佳答案
我的猜测是您将立方体背面的顶点以错误的方向缠绕,使它们的法线指向立方体的内部而不是外部。 3d 代码中一个非常常见的优化是只绘制法线朝向相机的三角形。
关于c# - XNA 倍数立方体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24332813/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!