- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在使用 XNA 时遇到了一个奇怪的问题。
我一直在学习以下教程: http://www.i-programmer.info/projects/119-graphics-and-games/1108-getting-started-with-3d-xna.html
我已经完成了教程,但我完成的立方体呈现如下:
如您所见,某些顶点不会根据立方体的旋转进行渲染。
如果旋转被移除,立方体呈现如下:
我的完整代码如下(更新:这是固定代码,正确呈现):
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace _3DTutorial {
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game {
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
// Tut items
private BasicEffect effect;
private VertexPositionNormalTexture[] cube;
private float angle = 0;
public Game1() {
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize() {
// TODO: Add your initialization logic here
effect = new BasicEffect(graphics.GraphicsDevice);
effect.AmbientLightColor = new Vector3(0.0f, 1.0f, 0.0f);
effect.DirectionalLight0.Enabled = true;
effect.DirectionalLight0.DiffuseColor = Vector3.One;
effect.DirectionalLight0.Direction = Vector3.Normalize(Vector3.One);
effect.LightingEnabled = true;
Matrix projection = Matrix.CreatePerspectiveFieldOfView(
(float)Math.PI / 4.0f,
(float)this.Window.ClientBounds.Width / (float)this.Window.ClientBounds.Height,
1f,
10f
);
effect.Projection = projection;
Matrix V = Matrix.CreateTranslation(0f, 0f, -10f);
effect.View = V;
RasterizerState rs = new RasterizerState();
rs.FillMode = FillMode.WireFrame;
graphics.GraphicsDevice.RasterizerState = rs;
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent() {
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
cube = MakeCube();
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent() {
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime) {
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
angle = angle + 0.005f;
if (angle > 2 * Math.PI) {
angle = 0;
}
Matrix R = Matrix.CreateRotationY(angle) * Matrix.CreateRotationX(.4f);
Matrix T = Matrix.CreateTranslation(0.0f, 0f, 5f);
effect.World = R * T;
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
foreach (EffectPass pass in effect.CurrentTechnique.Passes) {
pass.Apply();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, cube, 0, (cube.Length / 3));
}
base.Draw(gameTime);
}
protected VertexPositionNormalTexture[] MakeCube() {
VertexPositionNormalTexture[] vertexes = new VertexPositionNormalTexture[36];
Vector2 Texcoords = new Vector2(0f, 0f);
// A square made of two triangles
Vector3[] face = new Vector3[6];
// First triangle - bottom left
face[0] = new Vector3(-1f, -1f, 0.0f);
// First triangle - top left
face[1] = new Vector3(-1f, 1f, 0.0f);
// First triangle - top right
face[2] = new Vector3(1f, 1f, 0.0f);
// Second triangle - top right
face[3] = new Vector3(1f, 1f, 0.0f);
// Second triangle - bottom right
face[4] = new Vector3(1f, -1f, 0.0f);
// Second triangle - bottom left
face[5] = new Vector3(-1f, -1f, 0.0f);
Matrix RotY90 = Matrix.CreateRotationY(-(float)Math.PI / 2f);
Matrix RotX90 = Matrix.CreateRotationX(-(float)Math.PI / 2f);
for (int i = 0; i <= 2; i++) {
// Front face
vertexes[i] = new VertexPositionNormalTexture(
face[i] + Vector3.UnitZ,
Vector3.UnitZ,
Texcoords
);
vertexes[i + 3] = new VertexPositionNormalTexture(
face[i + 3] + Vector3.UnitZ,
Vector3.UnitZ,
Texcoords
);
// Back face
vertexes[i + 6] = new VertexPositionNormalTexture(
face[2 - i] - Vector3.UnitZ,
-Vector3.UnitZ,
Texcoords
);
vertexes[i + 6 + 3] = new VertexPositionNormalTexture(
face[5 - i] - Vector3.UnitZ,
-Vector3.UnitZ,
Texcoords
);
// Left face
vertexes[i + 12] = new VertexPositionNormalTexture(
Vector3.Transform(face[i], RotY90) - Vector3.UnitX,
-Vector3.UnitX,
Texcoords
);
vertexes[i + 12 + 3] = new VertexPositionNormalTexture(
Vector3.Transform(face[i + 3], RotY90) - Vector3.UnitX,
-Vector3.UnitX,
Texcoords
);
// Right face
vertexes[i + 18] = new VertexPositionNormalTexture(
Vector3.Transform(face[2 - i], RotY90) + Vector3.UnitX,
Vector3.UnitX,
Texcoords
);
vertexes[i + 18 + 3] = new VertexPositionNormalTexture(
Vector3.Transform(face[5 - i], RotY90) + Vector3.UnitX,
Vector3.UnitX,
Texcoords
);
// Top face
vertexes[i + 24] = new VertexPositionNormalTexture(
Vector3.Transform(face[i], RotX90) + Vector3.UnitY,
Vector3.UnitY,
Texcoords
);
vertexes[i + 24 + 3] = new VertexPositionNormalTexture(
Vector3.Transform(face[i + 3], RotX90) + Vector3.UnitY,
Vector3.UnitY,
Texcoords
);
// Bottom face
vertexes[i + 30] = new VertexPositionNormalTexture(
Vector3.Transform(face[2 - i], RotX90) - Vector3.UnitY,
-Vector3.UnitY,
Texcoords
);
vertexes[i + 30 + 3] = new VertexPositionNormalTexture(
Vector3.Transform(face[5 - i], RotX90) - Vector3.UnitY,
-Vector3.UnitY,
Texcoords
);
}
return vertexes;
}
}
}
感谢任何帮助。
最佳答案
我会把它放在评论中,但我还没有这样做的特权。
我这里没有安装 XNA,所以我无法对此进行测试,但看起来你的脸被绘制成面向错误的方向。
人脸总会有可见的一面和透明的一面。穿过你的脸,把它们翻过来。当您这样做时,您会看到它们出现和消失。
关于c# - XNA 原语未按预期呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13521425/
我对java有点陌生,所以如果我犯了一个简单的错误,请原谅我,但我不确定我哪里出错了,我收到的错误是“预期的.class,预期的标识符,而不是声明, ';'预期的。”我尝试了不同的方法,并从这些方法中
This question already has answers here: chai test array equality doesn't work as expected (3个答案) 3年前
我正在学习 Java(对不起,我的英语很差,这不是我的母语),当我在 Eclipse (JavaSE-1.7) 中在我输入的每个“try”中执行“try-finally” block 时,会出现以下消
我收到两个错误,指出 token 上的语法错误,ConstructorHeaderName expected instead & token “(”上的语法错误,< expected 在线: mTM.
我找不到错误。 Eclipse 给我这个错误。每个 { } 都是匹配的。请帮忙。 Multiple markers at this line - Syntax error on token “)”,
代码: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class DoubleIt extends
我正在用 python(Vs 代码)编写代码,但出现此错误: Expected ")" Pylance 错误发生在:def main() 我试着运行我的 main 并将它打印到我的屏幕上。我用谷歌搜
我正在尝试按照 documentation 中的建议使用异步函数。但我收到此错误 意外的 token ,预期 ( async function getMoviesFromApi() { try
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
第一行包含一个表示数组长度的整数p。第二行包含用空格分隔的整数,这些整数描述数组中的每个元素。第三行打印一个整数,指示负数组的数量。 package asgn3; import java.util.*
好的,我是初学者,我必须修复此 java 表达式语言代码才能在我的系统 (Windchill) 中工作,但看起来我在语法中遗漏了一些内容: LWCNormalizedObject lwc =
我无法编译我的程序! 我想我缺少一个花括号,但我怎么也看不出在哪里! import javax.swing.*; import java.awt.*;
我的 jQuery 代码有问题,我的 Firebug 向我发出警告:需要选择器。 这是代码: $("img[id$='_tick']").each(function() { $(this).c
我的新类(class) Fountainofyouth 遇到了问题。尝试构建整个项目后,调试器显示 warning: extended initializer lists only available
我已经从 Java 转向 CPP,并且正在努力围绕构造构造函数链进行思考,我认为这是我的问题的根源。 我的头文件如下: public: GuidedTour(); GuidedTour(string
鉴于以下 for(var i=0; i< data.cats.length; i++) list += buildCategories(data.cats[i]); jsLint 告诉我 Expect
我有这个 json,但 Visual Studio Code 在标题中给了我警告。 [ { "title": "Book A", "imageUrl": "https:
我正在尝试编写一个有条件地禁用四个特殊成员函数(复制构造、移动构造、复制赋值和移动赋值)的包装类,下面是我用于测试目的的快速草稿: enum class special_member : uint8_
所以我用 F# 编写了一个非常简单的程序,它应该对 1000 以下的所有 3 和 5 的倍数求和: [1..999] |> List.filter (fun x -> x % 3 = 0 || x %
我是一名优秀的程序员,十分优秀!