Jump to content

  • Log In with Google      Sign In   
  • Create Account


consti

Member Since 12 Sep 2007
Offline Last Active Jan 25 2014 06:11 PM

Topics I've Started

Elapsed time and Sin

21 October 2013 - 09:54 PM

Hello, in this OpenTK application why can you get the perfect scale with Math.PI?

 
time = (time >= Math.PI) ? 0.0 : time + e.Time;
variableScale = (float)(Math.Sin(time));

I know that Sin works best for 0..360 circle degrees range, but Math.PI related to time is strange.

 

If you have any references about and links to share please post here. Thanks.smile.png

 


Understanding Tiled TMX gids.

15 April 2013 - 09:17 AM

Have any one looked at the Tiled format?

 

One thing that I try to understand is if a layer contains tiles from two tilesets, then how you can understand which tile originates from a specific tileset.

 

For example:

f tileset A consists of a region of numbers 1 to 19 then it will have first GID 1.

If tileset B consists of a region of numbers 20 to 29 then it will have first GID 20.

And so on...

 

If in a Layer I have these tiles: 1, 10, 2, 20, 15, 25

Then they match this pattern of tilesets: A, A, A, B, A, B

 

What I really don't understand is how you can estimate in programming how this happens. I have looked at various TMX parsers but I can't figure out how exactly they achieve that.


XNA Touch Movement

30 March 2012 - 09:35 PM

Hello, I have a piece of code where I would like to move the player up and down with touch input. If the touch is made just above the player position then player moves up and the same goes for opposite direction.

The problem I have is that when the position of player is the same as the touch position then I have a nasty filckering (player moves up for one moment then moves down, and keep going as long as I have the pressed event going on). I tried to eliminate the flickering but I can't figure out what is going on. Any ideas or a better preffered way will be much welcomed.

public override void Update(GameTime gameTime)
  {
   #region Input
  
   NinjaGame.Instance.TouchCollection = TouchPanel.GetState();
  
   foreach (TouchLocation tl in NinjaGame.Instance.TouchCollection)
   {
    if (tl.State == TouchLocationState.Pressed ||
	    tl.State == TouchLocationState.Moved)
    {	
	 float playerPosHalfHeight = this.Position.Y + (this.Texture.Height/2);
	
	 // Something fishy is going on here...

	 if (tl.Position.Y >= playerPosHalfHeight)
	  this.Velocity = new Vector2(0f, 0.25f);
	
	 if (tl.Position.Y < playerPosHalfHeight)
	  this.Velocity = new Vector2(0f, -0.25f);
    }
   
    if (tl.State == TouchLocationState.Released)
    {
	 this.Velocity = new Vector2(0f, 0f);
    }
   }
  
   #endregion
  
   base.Update(gameTime);
   /* In other words... <img src='http://public.gamedev.net//public/style_emoticons/default/tongue.png' class='bbc_emoticon' alt=':P' />
   float delta = (float)gameTime.ElapsedGameTime.Milliseconds;
   Position += new Vector2(Velocity.X * delta, Velocity.Y * delta);
   */
 
   #region Screen bounds check (top / bottom)
   if (this.Position.Y + this.Texture.Height > NinjaGame.Instance.GraphicsDevice.Viewport.Height)
    this.Position = new Vector2(this.Position.X,
							    NinjaGame.Instance.GraphicsDevice.Viewport.Height -
							    this.Texture.Height);
  
   if (this.Position.Y < 0f)
    this.Position = new Vector2(this.Position.X, 0f);
   #endregion
 
  }

Thanks, happy coding.

VBO: How to draw many points

07 February 2011 - 07:39 AM

Hi there, in this tutorial I learnt to draw a single point.
http://ogldev.atspace.org/www/tutorial02/tutorial02.html
Also in later lessons I learnt how to give motion to vertices.

What I would like to do is to know how can I create a rain effect?
  • How to draw many points (raindrops)
  • How to know the speed of each raindrop.
  • How to know the bounds of lower and upper screen (inside the shader or outside in C++ code)?
Any help will be much appreciated, thanks. :)

[SlimDX] How to draw lines

05 February 2011 - 10:58 PM

Hi there guys, I try to learn DirectX by looking at Drunken Hyena tutorials
http://www.drunkenhyena.com/cgi-bin/view_net_article.pl?chapter=2;article=21#Drawing_Lines

Now I would like to draw a few random lines on the screen, I don't know how exactly to do it. I use an array called data and fill it up with struct data but obviously is wrong. Any ideas? :)

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

namespace SlimDXGUI
{
	class Program
	{
		public struct TransformedColored
		{
			public Vector3 Position { get; set; }
			public int Color { get; set; }		
		}
		
		public class Form1 : Form
		{
			Direct3D d3d;
			Device device;
			TransformedColored[] data;
			VertexBuffer vertexBuffer;
			
			protected override void OnLoad(EventArgs e)
			{
				d3d = new Direct3D();
				
				PresentParameters pp = new PresentParameters();
				pp.SwapEffect = SwapEffect.Discard;
				pp.DeviceWindowHandle = Handle;
				pp.Windowed = true;
				pp.BackBufferWidth = Width;
				pp.BackBufferHeight = Height;
				pp.BackBufferFormat = Format.A8R8G8B8;
				
				device = new Device(d3d, 0, DeviceType.Hardware, Handle,
			                	CreateFlags.HardwareVertexProcessing, pp);
				
				data = new TransformedColored[100];
				
				Random rnd = new Random(DateTime.Now.Millisecond);
				
				for (int i = 0; i < data.Length; i++)
				{
					data[i] = new TransformedColored();
					float x = (float) rnd.Next(0, Width);
					float y = (float) rnd.Next(0, Height);
					data[i].Position = new Vector3(x, y, 0f);
					data[i].Color = Color.Black.ToArgb();
				}
			}
			
			protected override void OnClosed(EventArgs e)
			{
				device.Dispose();
				d3d.Dispose();
			}
			
			public void Render()
			{
				device.Clear(ClearFlags.Target, new Color4(Color.White), 0, 0);
				
				device.BeginScene();
				
				device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
				
				device.DrawUserPrimitives(PrimitiveType.LineList,
				                      	ClientSize.Width / 2, 
				                     	data);
				
				device.EndScene();
				
				device.Present();
			}
		}
		
		[STAThread]
		public static void Main(string[] args)
		{
			using (Form1 form = new Form1())
			{
				Application.Run(form);
			}
		}
	}
}

PARTNERS