# TariqoO

Member

10

## Posts posted by TariqoO

1. ### Map tiles calculate

I think i just need to convert from puzzle(background) to map coordinate

bump

3. ### Map tiles calculate

                    for (int x = 0; x < map.PPuzzle.TileSize / TileWidth; x++)
{
for (int y = 0; y < map.PPuzzle.TileSize / TileHeight; y++)
{
int mapx = x + ((px + fpx)/*Current Puzzle*/ * map.PPuzzle.TileSize / TileWidth);
int mapy = y + ((py + fpy)/*Current Puzzle*/ * map.PPuzzle.TileSize / TileHeight);
int drawx = x  * TileWidth + drawX;
int drawy = y * TileHeight + drawY;
byte[] b = new byte[] { 0/*Blue*/, 0/*Green*/, 255/*Red*/ , 0/*useless*/ };
if (map.IsValid((ushort)(mapx), (ushort)(mapy)))
{
b = new byte[] { 0/*Blue*/, 255/*Green*/, 0/*Red*/ , 0/*useless*/ };
}
int bgr = BitConverter.ToInt32(b, 0);
st.WriteRange(Helper.GetDiamond(drawx, drawy, TileWidth, TileHeight, bgr));
primitivecount += 4;
}
}


That fixed it but : (

As you can see there is something wrong in the map coordinates the bridge tiles should be drawn with green color

In the game if i walked to down

X,Y increased

To up

both decreased

To Right

X increased , Y decreased

To Left

Y increased , X decreased

so i guess its really an isometric map so do i need to deal with this using math

or i just need to transform the buffer

Thanks

I really want to do it myself, but i tried a lot of things nothing worked

I'm talking seriously i spent many hours trying to complete it

At this rate i will waste my time and it looks like i have a lot of problems with math

So i will be really thankful for anyone will help me

bump

5. ### Hope someone can have a look at my work

Looks interesting, from the video i think you should hide the cursor

6. ### Map tiles calculate

Hi, i want to make a map editor for some game(not mine)

So it uses some files contains paths of textures the game loads it and draw it as a background

I did that too but now i want convert the texture to list of tiles

I mean the tiles inside the texture

Thats my full code

public void CameraMoved()
{

{
t.Texture.Dispose();
}
Textures.Clear();
Textures.Capacity = 0;
int XCoordsToShow = (int)Math.Min(RenderWidth / map.PPuzzle.TileSize/*At the most 256 and some maps use 128*/ + 1, map.PPuzzle.Size.Width);
int YCoordsToShow = (int)Math.Min(RenderHeight / map.PPuzzle.TileSize + 1, map.PPuzzle.Size.Height);

int fpx = Camera.X / map.PPuzzle.TileSize;
int fpy = Camera.Y / map.PPuzzle.TileSize;

if (bfr != null)
bfr.Dispose();
int numberoftiles = (RenderWidth / TileWidth + (RenderWidth % TileWidth)) * (RenderHeight / TileHeight + (RenderWidth % TileHeight));
bfr = new VertexBuffer(renderMgr.Device, numberoftiles * 20, Usage.None, VertexFormat.PositionRhw | VertexFormat.Diffuse, Pool.Default);
st = bfr.Lock(0, 0, LockFlags.None);
primitivecount = 0;
for (int px = 0; px < XCoordsToShow; px++)
{
for (int py = 0; py < YCoordsToShow; py++)
{
int drawX = px;
int drawY = py;
drawX *= map.PPuzzle.TileSize;
drawY *= map.PPuzzle.TileSize;
int pzlindex = map.PPuzzle.Entries[px + fpx, py + fpy];
string dds = Static.GetANI(Static.ConquerPath + "\\" + map.PPuzzle.ANIPath,
pzlindex)[0];
t.Texture = Helper.LoadTexture(renderMgr.Device, dds);/*256X256 DDS File*/
t.X = drawX;
t.Y = drawY;
#region TilesInside
for (int x = 0; x < map.PPuzzle.TileSize/TileWidth; x++)
{
for (int y = 0; y < map.PPuzzle.TileSize/TileHeight; y ++)
{
/*The problem in this 4 numbers
* I know its wrong way but i tried other ways and?!
*/
int mapx = x + ((px + fpx)/*Current Puzzle*/+ TileWidth);
int mapy = y + ((py + fpy)/*Current Puzzle*/+ TileHeight);
int drawx = x + drawX;
int drawy = y + drawY;
byte[] b = new byte[] { 0/*Blue*/, 0/*Green*/, 255/*Red*/ , 0/*useless*/ };
if (map.IsValid((ushort)mapx, (ushort)mapy))
{
b = new byte[] { 0/*Blue*/, 255/*Green*/, 0/*Red*/ , 0/*useless*/ };
}
int bgr = BitConverter.ToInt32(b, 0);
st.WriteRange(Helper.GetDiamond(drawx, drawy, TileWidth, TileHeight, bgr));
primitivecount += 4;
}
}
#endregion
}
}
bfr.Unlock();
}


the problem is exactly here :

                            int mapx = x + ((px + fpx)/*Current Puzzle*/+ TileWidth);
int mapy = y + ((py + fpy)/*Current Puzzle*/+ TileHeight);
int drawx = x + drawX;
int drawy = y + drawY;


what i want to see(from other viewer) :

what i'm seeing :

What i want to know is how can i calculate (MapX,MapY) , (ScreenX,ScreenY (I think that will be easier if i knew the map coordinates )) << i feel like i'm programming now xD

7. ### SharpDX Drawing rectangle

@xoofx

Actually i'm planing to draw the tiles in different colors(depends on coordinate validity)

so using long lines is not an option

Thank you for you amazing library and you perfect help.

8. ### SharpDX Drawing rectangle

You are using PrimitiveType.LineStrip which is as stated in the doc Renders the vertices as a single polyline. Instead you should use PrimitiveType.LineList which is "Renders the vertices as a list of isolated straight line segments.". You will have to change your points gen also that you have (p0-p1), (p1-p2), (p2-p3)....etc.

Thanks .. didn't get that part? can you explain

After changing from LineStrip to LineList this is the result:

Some lines missing maybe because i didn't do that?

9. ### SharpDX Drawing rectangle

Hi, i tried many times searched and used many methods

It did'nt work

The one on right is what i want to see

Full test code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SharpDX.Direct3D9;
using SharpDX;

namespace GridDrawTest
{
public partial class Form2 : Form
{
public struct CUSTOMVERTEX
{
public float x, y, z, rhw;
public int color;
public CUSTOMVERTEX(float x, float y, float z, float rhw, int c)
{
this.x = x;
this.y = y;
this.z = z;
this.rhw = rhw;
color = c;
}
}
RenderManager Mgr;
VertexBuffer bfr;
public Form2()
{
InitializeComponent();
pictureBox2.Image = new Bitmap(RenderWidth, RenderHeight);
Mgr = new RenderManager(pictureBox1.Handle/*Handle*/,RenderWidth,RenderHeight);
int numberoftiles = (RenderWidth / TileWidth) * (RenderHeight / TileHeight);
bfr = new VertexBuffer(Mgr.Device, numberoftiles * 4, Usage.None, VertexFormat.PositionRhw | VertexFormat.Diffuse, Pool.Default);
DataStream st = bfr.Lock(0, 0, LockFlags.None);
Graphics myImageGraphics = Graphics.FromImage(pictureBox2.Image);
for (int x = 0; x < RenderWidth / TileWidth; x++)
{
for (int y = 0; y < RenderHeight / TileHeight; y++)
{
int tx = x * (TileWidth);
int ty = y * (TileHeight);
System.Drawing.Rectangle r = new System.Drawing.Rectangle(tx,ty,TileWidth,TileHeight);
myImageGraphics.DrawRectangle(new Pen(System.Drawing.Color.Red), r);
byte[] b = new byte[] { 0/*Blue*/, 0/*Green*/, 255/*Red*/ , 0/*useless*/ };
int bgr = BitConverter.ToInt32(b,0);
CUSTOMVERTEX[] cv = new CUSTOMVERTEX[] {
new CUSTOMVERTEX(r.Right, r.Y, 0, 1f, bgr),
new CUSTOMVERTEX(r.X, r.Top, 0, 1f, bgr),
new CUSTOMVERTEX(r.Left, r.Y, 0, 1f, bgr),
new CUSTOMVERTEX(r.X, r.Bottom, 0, 1f, bgr),
};
st.WriteRange(cv);
primitiveCount += 4;
}
}
myImageGraphics.Dispose();
bfr.Unlock();
Mgr.OnDraw += new SharpDX.Action(Mgr_OnDraw);
while (true)
{
if (ActiveForm == this)
Mgr.Render();
}
}));
render.Start();
}
int primitiveCount = 0;
void Mgr_OnDraw()
{
Mgr.Device.Clear(ClearFlags.Target, new ColorBGRA(this.BackColor.ToArgb()), 0f, 1);
Mgr.Device.SetStreamSource(0, bfr, 0, 20/*sizeof(CUSTOMVERTEX)*/);
Mgr.Device.VertexFormat = VertexFormat.Diffuse | VertexFormat.PositionRhw;
Mgr.Device.DrawPrimitives(PrimitiveType.LineStrip, 0, primitiveCount);
}
int RenderWidth = 200;
int RenderHeight = 200;
int TileWidth = 32;
int TileHeight = 32;

private void Form2_Load(object sender, EventArgs e)
{

}

private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Environment.Exit(0);
}
}
}