문제

I'm working on a math game where the numbers (0-99) are used for the questions and the answers (like standard billiard balls, but they only go to 15 normally).

So, I'm thinking it'd be a lot smarter to generate at -least- the numbers programmatically rather than modelling 99 different balls in 3DSMax or similar.

I'm working in C#/XNA but can handle an explanation in DX11/C++ as well.

I'm not looking for code, but rather an approach: sort of a bullet list that would look like this (if this were anything close to correct):

  • Build a shpere in 3DS that is white and has a stripe on it.
    • Or, should the strip be part of the texture I later add?
  • During DrawModel change the color of the ball (if solid) or stipe (if striped)
  • Somehow add the number to the ball in a way that it looks like the same quality as the rest of the ball

Perhaps there's a magic way to take a texture and wrap it around a sphere without any distortion, and then I could just generate textures and stick 'em on the spheres. But as you can guess, I don't know which way to go here.

Thanks for any direction!

도움이 되었습니까?

해결책 2

If you're looking to tackle it with XNA / MonoGame / ANX, the approach really depends on whether you're using the Reach profile or HighDef profile.

With the reach profile, I'd suggest:

  1. Creating a RenderTarget
  2. Clear the render target to the colour of the ball
  3. Draw the white stripe(s) on to the render target
  4. Draw the number onto the render target
  5. Create dynamically a (or use an existing) Sphere mesh
  6. Render the sphere mesh using the Basic effect and the rendertarget texture

With the high profile, it's a case writing a pixel shader that:

  1. takes a "white" texture, a "colour" texture, a colour and a "number" texture
  2. renders the white texture white
  3. renders the colour texture the supplied colour
  4. renders the numbers texture

(I'd suggest rendering the number texture using a similar technique to the Reach profile example. Rendering text is a pain so may as well take advantage of the inbuilt stuff where possible). There is an re-colouring example provided by the (former) XNA team at http://create.msdn.com

다른 팁

You will want to print your numbers on texture maps. This texture is effectively a "decal", which is pasted onto part of your sphere. An easy way to implement a simple, fixed decal like this is to write a pixel shader which determines if the point is inside or outside the region of the decal. If it is not, you can make an additional test to determine if the pixel should be the white background, or the colored stripe.

You can map the decal to your sphere by either specifying the appropriate texture coordinates for each vertex or, alternately (and possibly more cleanly), you could write a pixel shader that computes the texture coordinates from the 3D model coordinates.

Either way, you will always get distortion on a sphere. I would recommend you look at map projections, which all solve your basic problem of converting between a flat image and a sphere. I would specifically suggest looking at the "gnomonic" and "orthographic" projections, both of which are simple to understand and to implement.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top