XNA: Classes with Texture2D to be treated as one

Summarized problem:
I have an "animation" class that I can treat as a Texture2D field as needed. I do not want to inherit from the class or their parents. I'd rather not create a parent class of both the animation class and a "container" for a Texture2D, though this is the only way to accomplish what I want.

Context: https://pastebin.com/PTgJuYEU
It's an extremely simple class that can change. His goal is to use a Texture2D for the external processing of spreadsheets and so on. It is used in an ECS, but probably not as a component as I have it now.

For example, I would like to use it as a character for a Texture2D in Draw calls (this can be done with the & # 39; texture & #;; property) and also be kept in the same field and converted to it Treat it again as an animation class , (If anyone thinks there is a much better implementation, please let me know.)

Thank you in advance.

EDIT: If there is a way, I could make something perfect:
spriteBatch.Draw (Anim as Texture2D, Vector2.Zero, Color.White);

xna – Simplify Mathecode for Matrix – Sun Billboarding

When trying to set the correct position of my Sun billboard in my 3D game. I tried a long time to get it working right, but I wonder why this code has to be so complicated:

sun.sprite.Position = Vector3.Transform (Vector3.Transform (-sun.lightDir,
Quaternion.Inverse (world.Rotation)), Quaternion.Inverse (myRelativeRotation));

Can I simplify this expression? At least I tried to change it:

sun.sprite.Position = Vector3.Transform (-sun.lightDir,
Quaternion.Inverse (world.Rotation) * Quaternion.Inverse (myRelativeRotation)) 

However, this leads to different results, so that the sun is in the wrong place.

c # – XNA 4.0 To combine triangular vertices in 3D

Preview for the problem:

I'm doing a similar game to Minecraft (a game where the world is made up of dice), but the fps of the game are getting low only by rendering a small number of dice in the world.

So I decided to use the Combine / Margin technique to improve it. I want to combine cubes that are of the same type and whose positions are next to each other.

Suppose I have 4 faces of cubes juxtaposed in this order:

[+] [+]

[+] [+]

Right now: I rendered each face with 2 triangles so that I render all faces with 8 triangles.

Improvement that I would like to make: I want to render these surfaces with only two triangles, but keep the textures where they are. This means that you only use 2 tringles for 2 faces and 4 for this area.

Outside the topic:

Currently I use:

  • Frustum wheezing
  • Cube faces that lie on top of each other are not rendered.

Which fps improvement techniques do you recommend to use?
At the moment I only make 1500 faces at the same time [3000 triangles] My game reaches about 25 ~ fps.

xna – Trying to get vertex shaders to work with Monogame 2D

If I do not use the vertex shader, white textures appear. This is the default color. After adding the vertex shader, the screen is black.

I think there is something wrong with the matrices I give to the shader, but I'm not sure.

                #if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#otherwise
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

Matrix WorldViewProjection;

struct VertexShaderInput
{
float4 position: SV_POSITION;
float4 color: COLOR0;
float2 texCoord: TEXCOORD0;
};

struct VertexShaderOutput
{
float4 position: SV_POSITION;
float4 color: COLOR0;
float2 texCoord: TEXCOORD0;
};



VertexShaderOutput MainVS (in the input "VertexShaderInput")
{
VertexShaderOutput output = (VertexShaderOutput) 0;

output.Position = mul (input.Position, WorldViewProjection);
output.Color = input.Color;

Return the output;
}

float4 MainPS (input VertexShaderOutput): COLOR
{
Return input. Color;
}

Technique BasicColorDrawing
{
Pass P0
{
VertexShader = Compile VS_SHADERMODEL MainVS ();
PixelShader = PS_SHADERMODEL Compile MainPS ();
}
};

My projection matrix (The default that uses sprite batch).

Projection = Matrix.CreateTranslation (-0.5f, -0.5f, 0) * Matrix.CreateOrthographicOffCenter (0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, -1)

Setting my WorldViewProjection matrix.

negEffect.Parameters["WorldViewProjection"].SetValue (projection);

Just the projection because I turned off my camera to make debugging easier.

The drawing code.

GraphicsDevice.SetRenderTarget (renderTarget);
GraphicsDevice.Clear (Color.Black);
var debugMatrix = debugCamera.GetViewMatrix ();



spriteBatch.Begin (SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, negEffect);


spaceObjectManager.Draw (spriteBatch);
spaceEnemyManager.Draw (spriteBatch);
playerShip.projectileManager.Draw (spriteBatch);
playerShip.Draw (spriteBatch);

spriteBatch.End ();

GraphicsDevice.SetRenderTarget (null);



spriteBatch.Begin (SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null);
spriteBatch.Draw (renderTarget, new Rectangle (0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
spriteBatch.End ();


physicsDebug.RenderDebugData (ref SimProjection, ref debugMatrix);

VertexShader off.

VertexShader off

VertexShader on.

VertexShader on

Thank you in advance!

XNA – How do I scale sizes and speeds for a minimap?

I'm rebuilding the arcade game StarGate and need to create a mini map. However, I have problems scaling the minimap textures to fit into the radar box and making sure that the speed of scrolling is proportional to the main map and the mini map.

My textures are the size below:

  1. Complete page with scrolling: 4800 x 620
  2. Screen size 960×720

StarGate screenshot below:
Enter the image description here

xna – understand the semantics of the quaternion class

I'm having trouble understanding the semantics of some members of the Quaternion class. The documents are not helpful, and tutorials that try to explain quaternions use a lot of math, which is not helpful to me because I just do not have a proper background for it.

My main questions are currently:

Is there a difference between Multiply and Concatenate?

What is the exact difference between Inverse and Negate?

xna – MonoGame project can not be deployed for BlueStack (ADB0000: closed)

I'm using MonoGame 3.6 with the Visual Studio 2017 community and trying to deploy as an Android emulator on BlueStack. VS can see Bluestack and allow "deploy" to start, but ends with this error:

Severity Code Description Error in the status file of the project file line
ADB0000: Deployment failed. Mono.AndroidTools.AdbException: closed
Mono.AndroidTools.Util.AggregateAsyncResult.CheckError (CancellationToken
token) in
E: A_work 293 s External androidtools Mono.AndroidTools Util AggregateAsyncResult.cs: line
72 at
Mono.AndroidTools.Adb.AdbClient.EndWriteCommandWithStatus (IAsyncResult
asyncResult) in
E: A_work 293 s External androidtools Mono.AndroidTools Adb AdbClient.cs: line
328 at
System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic (IAsyncResult
iar, Func2 endFunction, Action1 endAction, Promise of Task1, Boolean
requiredSynchronization) 0

I can also deploy the same project to other emulators like Google One or Genycom. The problem is with BlueStack

any idea? Many Thanks