Announcement

Collapse
No announcement yet.

Texture orientation when creating a cube

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Texture orientation when creating a cube

    (Windows, version 3.00 on Delphi)
    Hey there.

    I am currently implementing Texturing option in my editor and noticed a missorientation of faces
    Could you help me with my steaming brain about the orientation of faces when creating a cube?

    Viewport_Meshbuffer.Cube(1, 1, 1, TVector3f.Zero,
    Vector3f(abs(aVector.x),0.0 , 0.0), Vector3f(0.0, abs(aVector.y), 0.0),
    Vector3f(0.0, 0.0, abs(aVector.z)), aTexStart, aTexEnd, floatcolor ($ffffffff) , true);​

    This creates a cube which side faces are rotated​ on the side.
    Click image for larger version  Name:	grafik.png Views:	0 Size:	936.7 KB ID:	452
    Obviously I would like all side faces to be oriented the same. I feel like that I should know how to fix this by now but I am still struggeling with vertices ect.

    "
    Creates a 3D cube with the given parameters. Axis vectors define both orientation and size.
    ​"
    This is the thing that I dont get in my head. How these values define also orientation.
    Attached Files
    Last edited by Zimond; 01-22-2025, 04:26 PM.

  • #2
    A cube created using this function internally calls Plane six times to create sides, where the facing of the plane can be controlled, but the orientation of the texture coordinates is fixed. The original C++ code is actually very simple:
    Code:
    bool MeshBuffer::cube(int32_t const horizSections, int32_t const vertSections, int32_t const depthSections,
      Vector const& origin, Vector const& horizAxis, Vector const& vertAxis, Vector const& depthAxis,
      PointF const& initTexCoord, PointF const& endTexCoord, FloatColor const& color,
      bool const indicesClockwise)
    {
      Vector const horizShift = horizAxis * 0.5f;
      Vector const vertShift = vertAxis * 0.5f;
      Vector const depthShift = depthAxis * 0.5f;
    
      Vector const horizNormal = horizAxis.normalize();
      Vector const vertNormal = vertAxis.normalize();
      Vector const depthNormal = depthAxis.normalize();
    
      return
        plane(horizSections, vertSections, origin - depthShift, horizAxis, vertAxis, -depthNormal,
          initTexCoord, endTexCoord, color, indicesClockwise) && // Front face.
        plane(horizSections, vertSections, origin + depthShift, -horizAxis, vertAxis, depthNormal,
          initTexCoord, endTexCoord, color, indicesClockwise) && // Back face.
        plane(horizSections, depthSections, origin + vertShift, horizAxis, depthAxis, vertNormal,
          initTexCoord, endTexCoord, color, indicesClockwise) && // Top face.
        plane(horizSections, depthSections, origin - vertShift, -horizAxis, depthAxis, -vertNormal,
          initTexCoord, endTexCoord, color, indicesClockwise) && // Bottom face.
        plane(vertSections, depthSections, origin - horizShift, vertAxis, depthAxis, -horizNormal,
          initTexCoord, endTexCoord, color, indicesClockwise) &&  // Left face.
        plane(vertSections, depthSections, origin + horizShift, vertAxis, -depthAxis, horizNormal,
          initTexCoord, endTexCoord, color, indicesClockwise); // Right face.
    }
    In your case, one alternative is that you can just rotate the cube itself during creation by specifying rotation transform in the mesh buffer before calling "Cube" function. Another alternative is that you can build the cube yourself by calling "Plane" six times and specifying transformation matrix to ensure the desired orientation. Let me know if you need an example doing that, I think the code would be quite simple.

    P.S. As we're close to the release of a new version of the framework, there is a new release candidate available. If you want to try it for your project, please PM me or send an e-mail so I can give you the link.

    Comment


    • #3
      ooooooh. of course. that would also allow me to use 3d texture tiling settings. something that I just noticed is off when you create uneven things like walls.

      Thanks for the offer, but I can wait. I can save scenes now so I can "design" super simple stuff for now. My next step is implementing a script system similar to the one I used in my Asphyre based adventure creator. And then make it actually launchable. Starting at the very bottom of games : Pong. Some cubes moving around. At this point, as limited as it may be, I can call it a game engine and start to increase possibilities with each step. From Pong to Breakout with "destroyable" model references, from there some sprite like planes oriented to the camera for an arkanoid game with items and enemies thats the idea.
      Attached Files

      Comment


      • #4
        Code:
        Viewport_Meshbuffer.Plane(1,1,TVector3f.Zero - Vector3f(0.0,0.0,abs(aVector.z) / 2) //Front
        ,Vector3f(abs(aVector.x),0.0 , 0.0),Vector3f(0.0,abs(aVector.y) , 0.0),Vector3f (0,0,-1)
        ,aTexStart, aTexEndXY, floatcolor ($ffffffff), true);
        Viewport_Meshbuffer.Plane(1,1,TVector3f.Zero + Vector3f(0.0,0.0,abs(aVector.z) / 2) //Back
        ,Vector3f(abs(aVector.x)*-1,0.0 , 0.0),Vector3f(0.0,abs(aVector.y) , 0.0),Vector3f (0,0,+1)
        ,aTexStart, aTexEndXY, floatcolor ($ffffffff), true);
        Viewport_Meshbuffer.Plane(1,1,TVector3f.Zero + Vector3f(abs(aVector.x) / 2,0.0,0.0) //Right
        ,Vector3f(0.0,0.0,abs(aVector.z)),Vector3f(0.0,abs (aVector.y) , 0.0),Vector3f (+1,0,0)
        ,aTexStart, aTexEndYZ, floatcolor ($ffffffff), true);
        Viewport_Meshbuffer.Plane(1,1,TVector3f.Zero - Vector3f(abs(aVector.x) / 2,0.0,0.0) //Left
        ,Vector3f(0.0,0.0,abs(aVector.z)*-1),Vector3f(0.0,abs(aVector.y) , 0.0),Vector3f (-1,0,0)
        ,aTexStart, aTexEndYZ, floatcolor ($ffffffff), true);
        Viewport_Meshbuffer.Plane(1,1,TVector3f.Zero + Vector3f(0.0,abs(aVector.y) / 2,0.0) //Top
        ,Vector3f(abs(aVector.x),0.0,0.0),Vector3f(0.0,0.0 , abs(aVector.z)),Vector3f (0,+1,0)
        ,aTexStart, aTexEndXZ, floatcolor ($ffffffff), true);
        Viewport_Meshbuffer.Plane(1,1,TVector3f.Zero - Vector3f(0.0,abs(aVector.y) / 2,0.0) //Bottom
        ,Vector3f(abs(aVector.x)*-1,0.0,0.0),Vector3f(0.0,0.0 , abs(aVector.z)),Vector3f (0,-1,0)
        ,aTexStart, aTexEndXZ, floatcolor ($ffffffff), true);​​
        Worked great, plus now I can set X Y and Z for texture tiling. resulting in proper looking sides on walls
        Attached Files

        Comment


        • #5
          I'm glad you got it working, it looks very good!

          Comment

          Working...
          X