Jump to content
  • Advertisement
Sign in to follow this  
lukacs16

Texture problem

This topic is 2989 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

Hello! I have some picture, for example now I have 4 picture, and I can create a cuboid, and the texture this 4 picture (without bottom and top texture). So, how can I create a model, or 4 rectangle with this pictures, and stick those with the side... Or which is the best solution? Later I have to create different shape, for example pyramid or sphere, and I have to use more picture, not just one texture file... What is the best solution? I can create in XNA a arbitary shape of model, or just can reate a texture mesh, or how can I do this?

Share this post


Link to post
Share on other sites
Advertisement
hello lukacs16.

I can post you some code snippets where i create worldbox. hope it will help you a little. The code is on C# and SlimDX. It is few similar to Xna.


class WorlBox
{
private const int NUMBER_VERTICES = 24;
...
private void CreateGeometry()
{
// create geometry for world box
float halfSize = m_size / 2;

int allVerticesSize = NUMBER_VERTICES * PositionColoredTexturedVertex.SizeInBytes;

if(m_geometry != null) m_geometry.Dispose();

m_geometry = new VertexBuffer(m_sceneGraph.Device, allVerticesSize, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
DataStream stream = m_geometry.Lock(0, 0, LockFlags.None);
PositionColoredTexturedVertex[] v = new PositionColoredTexturedVertex[NUMBER_VERTICES];

int argb = m_color.ToArgb();

// posX
v[0] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y - halfSize, m_center.Z + halfSize, argb, 0, 1);
v[1] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y + halfSize, m_center.Z + halfSize, argb, 0, 0);
v[2] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y - halfSize, m_center.Z - halfSize, argb, 1, 1);
v[3] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y + halfSize, m_center.Z - halfSize, argb, 1, 0);

// posY
v[4] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y + halfSize, m_center.Z + halfSize, argb, 0, 1);
v[5] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y + halfSize, m_center.Z - halfSize, argb, 0, 0);
v[6] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y + halfSize, m_center.Z + halfSize, argb, 1, 1);
v[7] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y + halfSize, m_center.Z - halfSize, argb, 1, 0);

// posZ
v[8] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y - halfSize, m_center.Z + halfSize, argb, 0, 1);
v[9] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y + halfSize, m_center.Z + halfSize, argb, 0, 0);
v[10] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y - halfSize, m_center.Z + halfSize, argb, 1, 1);
v[11] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y + halfSize, m_center.Z + halfSize, argb, 1, 0);

// negX
v[12] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y - halfSize, m_center.Z - halfSize, argb, 0f, 1f);
v[13] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y + halfSize, m_center.Z - halfSize, argb, 0f, 0f);
v[14] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y - halfSize, m_center.Z + halfSize, argb, 1f, 1f);
v[15] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y + halfSize, m_center.Z + halfSize, argb, 1f, 0f);

// negY
v[16] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y - halfSize, m_center.Z - halfSize, argb, 0f, 1f);
v[17] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y - halfSize, m_center.Z + halfSize, argb, 0f, 0f);
v[18] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y - halfSize, m_center.Z - halfSize, argb, 1f, 1f);
v[19] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y - halfSize, m_center.Z + halfSize, argb, 1f, 0f);

// negZ
v[20] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y - halfSize, m_center.Z - halfSize, argb, 0f, 1f);
v[21] = new PositionColoredTexturedVertex(m_center.X + halfSize, m_center.Y + halfSize, m_center.Z - halfSize, argb, 0f, 0f);
v[22] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y - halfSize, m_center.Z - halfSize, argb, 1f, 1f);
v[23] = new PositionColoredTexturedVertex(m_center.X - halfSize, m_center.Y + halfSize, m_center.Z - halfSize, argb, 1f, 0f);

stream.WriteRange(v);
m_geometry.Unlock();

}
...
}




[StructLayout(LayoutKind.Sequential)]
public struct PositionColoredTexturedVertex : IEquatable<PositionColoredTexturedVertex>
{
/// <summary>
/// Gets or sets the position of the vertex by x axis.
/// </summary>
public float X
{
get { return m_position.X; }
set { m_position = new Vector3(value, m_position.Y, m_position.Z);}
}

/// <summary>
/// Gets or sets the position of the vertex by y axis.
/// </summary>
public float Y
{
get { return m_position.Y; }
set { m_position = new Vector3(m_position.X, value, m_position.Z); }
}

/// <summary>
/// Gets or sets the position of the vertex by z axis.
/// </summary>
public float Z
{
get { return m_position.Z; }
set { m_position = new Vector3(m_position.X, m_position.Y, value); }
}

/// <summary>
/// Gets or sets the position of the vertex.
/// </summary>
/// <value>The position of the vertex.</value>
[VertexElement(DeclarationType.Float3, DeclarationUsage.Position)]
private Vector3 m_position { get; set; }

/// <summary>
/// Gets or sets the color of the vertex.
/// </summary>
/// <value>The color of the vertex.</value>
[VertexElement(DeclarationType.Color, DeclarationUsage.Color)]
public int Color { get; set; }

/// <summary>
/// Gets or sets the tu texture coordinate.
/// </summary>
/// <value>The texture coordinates.</value>
public float Tu
{
get { return m_textureCoordinates.X; }
set { m_textureCoordinates = new Vector2(value, m_textureCoordinates.Y); }
}

/// <summary>
/// Gets or sets the tv texture coordinate.
/// </summary>
/// <value>The texture coordinates.</value>
public float Tv
{
get { return m_textureCoordinates.Y; }
set { m_textureCoordinates = new Vector2(m_textureCoordinates.X, value); }
}

/// <summary>
/// Represents the texture cordinates
/// </summary>
[VertexElement(DeclarationType.Float2, DeclarationUsage.TextureCoordinate)]
public Vector2 m_textureCoordinates { get; set; }

/// <summary>
/// Gets the size in bytes.
/// </summary>
/// <value>The size in bytes.</value>
public static int SizeInBytes
{
get { return Marshal.SizeOf(typeof(PositionColoredTexturedVertex)); }
}

/// <summary>
/// Gets the format.
/// </summary>
/// <value>The format.</value>
public static VertexFormat Format
{
get { return VertexFormat.Texture0 | VertexFormat.Position | VertexFormat.Diffuse | VertexFormat.Texture1; }
}

/// <summary>
/// Initializes a new instance of the <see cref="PositionColoredTexturedVertex"/> struct.
/// </summary>
/// <param name="x">The coordinate by the x axis.</param>
/// <param name="y">The coordinate by the y axis.</param>
/// <param name="z">The coordinate by the z axis.</param>
/// <param name="color">The color.</param>
/// <param name="tu">The horisontal texture coordinate.</param>
/// <param name="tv">The vertical texture coordinate.</param>
public PositionColoredTexturedVertex(float x, float y, float z, int color, float tu, float tv) : this()
{
m_position = new Vector3(x, y, z);
Color = color;
m_textureCoordinates = new Vector2(tu, tv);
}
...
}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!