Jump to content
  • Advertisement
Sign in to follow this  
JoshuaBaker

ObjectSpace Sprites Flipped

This topic is 2350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this has been posted before, yet iv never seen a percise answer to the question and hoped to get clarification.

I am drawing sprites using the DX9 Sprite class in ObjectSpace, but the textures are upside down. I have tried many solutions, but mostly are ineffectual. Does anyone know the cause of this issue? I am using SlimDX for this.


// My Transforms
device.Viewport = new Viewport(0, 0, 800, 600);
device.SetTransform(TransformState.Projection, Matrix.OrthoLH(800, 600, 0, 1));
device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0)));
device.SetTransform(TransformState.World, Matrix.Identity);

// Sprite code that works but is hackish
spritebatch.Transform = Matrix.Scaling(1,-1,1) * SpriteMatrix;
spritebatch.Begin(SpriteFlags.AlphaBlend | SpriteFlags.ObjectSpace);
spritebatch.Draw(tex, sourecrect, center, Matrix.zero, Color.White);
spritebatch.End();


I dislike having to scale every transform, this seems like iv got the solution wrong. If anyone can assuage my guilt by using a hack or shed some light on what exactly is causing this (is it a texture coordinate issue internal to sprite?) i would appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
Maybe the lookat method and up vector are making this. I use quaternions for years so I’m a little rusty.

Try to put this up vector: (0, -1, 0). Then try Matrix.LookAtLH(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 1, 0)));

If both work then it was the up vector and I will explain why.

Share this post


Link to post
Share on other sites

device.Viewport = new Viewport(0, 0, 800, 600);
device.SetTransform(TransformState.Projection, Matrix.OrthoLH(800, 600, 0, 1));
device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(0, -1, 0)));
device.SetTransform(TransformState.World, Matrix.Identity);


This makes the texture correct, but the transform is flipped y- is now going up with y+ going down.


device.Viewport = new Viewport(0, 0, 800, 600);
device.SetTransform(TransformState.Projection, Matrix.OrthoLH(800, 600, 0, 1));
device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 1, 0)));
device.SetTransform(TransformState.World, Matrix.Identity);

This does not fix the texture issue and also flips y- and y+.

Share this post


Link to post
Share on other sites
Well thanks for trying, perhaps ill just roll my own spritebatch class somehow.
BTW this is the entire program...just trying to get this specific feature to work so i stripped it to nothing to see exactly what all was happening.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using SlimDX;
using SlimDX.Direct3D9;
using SlimDX.Windows;

namespace MiniTri {
static class Program {
[STAThread]
static void Main() {
RenderForm form = new RenderForm("Sprite Test");
form.ClientSize = new Size(800, 600);
form.TopMost = true;
form.FormBorderStyle = FormBorderStyle.Fixed3D;
form.StartPosition = FormStartPosition.CenterScreen;
PresentParameters presentparameters;
presentparameters = new PresentParameters();
presentparameters.BackBufferWidth = form.ClientSize.Width;
presentparameters.BackBufferHeight = form.ClientSize.Height;
presentparameters.BackBufferFormat = Format.X8R8G8B8;
presentparameters.BackBufferCount = 1;
presentparameters.Multisample = MultisampleType.None;
presentparameters.MultisampleQuality = 0;
presentparameters.SwapEffect = SwapEffect.Discard;
presentparameters.DeviceWindowHandle = form.Handle;
presentparameters.Windowed = true;
presentparameters.EnableAutoDepthStencil = false;
presentparameters.AutoDepthStencilFormat = 0;
presentparameters.PresentFlags = 0;
presentparameters.FullScreenRefreshRateInHertz = 0;
presentparameters.PresentationInterval = PresentInterval.Default;
Device device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, presentparameters);
device.Viewport = new Viewport(0, 0, 800, 600);
device.SetTransform(TransformState.Projection, Matrix.OrthoLH(800, 600, 0, 1));
device.SetTransform(TransformState.View, Matrix.Identity);
device.SetTransform(TransformState.World, Matrix.Identity);
Sprite spritebatch = new Sprite(device);
ImageInformation info = ImageInformation.FromFile("testsprite.png");
Texture tex = Texture.FromFile(device, "testsprite.png", info.Width, info.Height, 1, Usage.None, info.Format, Pool.Managed, Filter.None, Filter.None, 0);
MessagePump.Run(form, () => {
device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
device.BeginScene();
spritebatch.Transform = Matrix.Translation(0,0,0);
spritebatch.Begin(SpriteFlags.AlphaBlend | SpriteFlags.ObjectSpace);
spritebatch.Draw(tex, new Rectangle(0, 0, info.Width, info.Height), Vector3.Zero, Vector3.Zero, Color.White);
spritebatch.End();
device.EndScene();
device.Present();
});
foreach (var item in ObjectTable.Objects)
item.Dispose();
}
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!