View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Texture coords for repeating texture along cylinder tube

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1laylay  Members

Posted 12 November 2012 - 04:35 AM

I have a bunch of cylinders attached to each other (like a long tube) I want to be able to texture it without any stretching, just a nice repeating texture going along it. I know how to wrap around it but not along it. The problem is that each cylinder segment of the tube aren't the same size so I can't just increase the v coord by 1 each time. How can this be calculated?

### #2Ashaman73  Members

Posted 12 November 2012 - 06:49 AM

Here's some pseudo code:
v_texture_coord = 0
scale = 1.0
for i=1...n do
cylinder = cylinder_array[i]
cylinder.start_v = v_texture_coord

v_texture_coord = v_texture_coord + cylinder.length * scale
cylinder.end_v =  v_texture_coord
end


Ashaman

### #3laylay  Members

Posted 12 November 2012 - 10:34 PM

Thanks. So pretty much I can just increase along the length of the segment? What are the start and end v coords for?

It seems to work anyway but I'm having a problem with wrapping around the pipe that I didn't notice. The last face on the cylinder segment is messed up. This is how I'm calculating it.

[source lang="cpp"] // loop through each point on the radius for (unsigned int i = 0; i < m_points; ++i) { // sin and cos displace the vertex in a radius float x = cos(Math::DegreesToRadians(degrees)) * m_radius; float y = sin(Math::DegreesToRadians(degrees)) * m_radius; // offset the vertex up and right to orientate it Vector3f point = position; point += right * x; point += up * y; // create the vertex Vertex vertex; vertex.position = point; vertex.normal = (point - position).Normalise(); vertex.texCoord = Vector2f((float)i / ((float)m_points - 1.0f), ycoord); m_vertices.push_back(vertex); // keep going around the radius degrees += 360.0f / (float)m_points - 1; }[/source]

What I think is happening is that the 0th vertex on the ring has a u texcoord of 0 but the last one is 1, that's going to cause problems I think. How should I handle it?

I have a feeling I'll have to have a duplicate vertex at the 0th position because it needs to be 0 for the first face but 1 for the last face. Kind of sucks.

Edited by laylay, 13 November 2012 - 12:05 AM.

### #4Brother Bob  Moderators

Posted 13 November 2012 - 04:30 AM

If you want the cylinder to have N points around, then you need N+1 vertices since the first and the last two vertices have different texture coordinates even though they have the same position. In your code, as far as I can see all you need to do it change the loop exit condition from < to <=.

### #5laylay  Members

Posted 13 November 2012 - 05:35 AM

Yeah I thought so, thanks for clarifying that though. There was a bit more work involved with getting it to work but it's wrapping around perfectly now.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.