- 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/
我可以将内容项目引用到非 XNA 项目(MonoGame,如果它很重要)? 最佳答案 不直接。 将内容项目引用添加到项目的功能仅适用于“XNA 游戏”和“XNA 游戏库”类型的项目。 当我想在 Win
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve thi
您如何看待 xna 和大型多人游戏?例如服务器和 100 个客户端?有没有很好的教程如何在 xna 中创建客户端服务器应用程序? 最佳答案 当然有关于如何做到这一点的教程。我个人使用 Lidgren
好的,所以我正在开发这个游戏,我是 XNA 的新手(我使用的是 4.0),我想做的是每次产生敌人时都有不同的纹理。 所以我有这些图像“image1.png”、“image2.png”等等。我希望它在每
我最近开始检查XNA。一切进展顺利,我什至开始了一个工作样本。困扰我的一件事是,每当我将鼠标放在游戏窗口上时,它就会消失。我不知道这是否是默认行为,但我想更改此设置以便可以看到鼠标。任何和所有建议,不
我刚从 XNA 开始,有一个关于轮换的问题。当你在 XNA 中将一个向量乘以一个旋转矩阵时,它会逆时针旋转。这个我明白。 但是,让我举一个我不明白的例子。假设我将一个随机艺术 Assets 加载到管道
我正在使用 Visual Studio 2010 Ultimate,在谷歌上搜索 XNA 下载后,我找到了这个页面: http://blogs.msdn.com/b/xna/archive/2010/
我有一个字典来存储SoundEffects,例如: public static Dictionary Hangok = new Dictionary(); 我从文件(正常.wav格式)加载声音,例如:
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 10年前关闭。 Improve this
好吧,我正在尝试为 3D XNA 游戏创建自己的物理引擎,但我在计算我应该将物体移动多少时遇到重力问题。 XNA 的游戏计时器每 16 毫秒出现一次,所以经过一些计算,并使用 9.81m/s 作为我的
我正在尝试对以下粒子系统进行修改。 http://create.msdn.com/en-US/education/catalog/sample/particle_3d 我有一个功能,当我按下Space
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be
也许这更像是一个数学问题而不是一个编程问题,但我一直在尝试在 XNA 中实现旋转卡尺算法。 我已经使用维基百科上详述的单调链从我的点集中推导出了一个凸包。 现在,我正在尝试对我的算法进行建模,以在此处
我正在 XNA 中制作一个简单的 2 人游戏,并开始研究保存玩家的高分。 我希望游戏能在 XBox 360 和 Windows 上运行,所以我必须使用框架来保存数据。 您似乎将数据保存到特定用户的玩家
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我需要使用不同字体大小的 spritefont,我必须为每个大小创建新的 spritefont 吗? 最佳答案 基本上是的。 有一个overload的 SpriteBatch.DrawString这为
我对在我的游戏中存储 *.txt 级别文件的位置和方式感到非常困惑。 我想要在我的游戏中提供一些随游戏一起安装的“预烘焙”关卡的可用性,以及用户创建自己的关卡的能力。 所以我所做的是在 Visual
我有一个足够简单的着色器,它支持多个点光源。 灯光存储为一组灯光结构(最大大小),当事件灯光发生变化时,我会传入事件灯光的数量。 问题出在 PixelShader 函数中: 这是基本的东西,从纹理中获
我有 19 张图像,它们是我的播放器的动画帧 在下面,我创建了 Frog 纹理数组,这是我的播放器。并且有 19 个图像。如何对它们进行动画处理。 公共(public)类纹理 { 公共(public)
所以,我要直截了本地说,我正在尝试在我正在制作的 XNA 游戏中制作一个聊天系统。我可以很容易地找出正在按下的键但是我无法知道实际键入的是什么。在我看来,他们好像在说:OemShifthello bi
我是一名优秀的程序员,十分优秀!