-2

Following the examples given in the Pascal-driven Castle Game Engine for drawing a mesh, I tried to draw a raycast vector visually using this particular piece of code for reference:


  procedure CreateMesh;
  begin
    Mesh := TCastleRenderUnlitMesh.Create(true);
    Mesh.SetVertexes([
      Vector4(-1, -1, -1, 1),
      Vector4( 1, -1, -1, 1),
      Vector4( 1,  1, -1, 1),
      Vector4(-1,  1, -1, 1),

      Vector4(-1, -1,  1, 1),
      Vector4( 1, -1,  1, 1),
      Vector4( 1,  1,  1, 1),
      Vector4(-1,  1,  1, 1)
    ], false);
    Mesh.SetIndexes([
      // line loop on Z = -1
      0, 1,
      1, 2,
      2, 3,
      3, 0,

      // line loop on Z = 1
      4, 5,
      5, 6,
      6, 7,
      7, 4,

      // connect Z = -1 with Z = 1
      0, 4,
      1, 5,
      2, 6,
      3, 7
    ]);

    // Later on in the code
    CreateMesh;

I was told on this particular thread, when I asked for clarification, that the numbers in "SetIndexes" indicate the order to draw the lines in correctly like I guessed, and that SetVertices set the vertices that you draw from and to. That is fine.

However, when I saw that "SetVertices" as it was in the example above didn't accept parameters and I needed parameters to get the player character's location precisely, I asked if it was okay to create my own function with parameters.

I didn't get a response, because they wanted me to figure things out for my self there to actually learn, which is fine, but knew the resourceful and responsible thing to do was to look up the function in the manual and see if it is pre-defined with a specific number of parameters,

But fortunately it wasn't, so I assumed it was probably a piece of code customly defined by the user in that case, rather than pre-programed into the engine's language.

I guessed then, that I could use the above code for reference to make my own custom SetVertices with parameters, and use the parameter's coordinates for the inputs of the vector coordinates, exactly like this:


  procedure CreateMesh(const AvatarTransform: TCastleTransform);
  begin
    Mesh := TCastleRenderUnlitMesh.Create(true);
    Mesh.SetVertexes([
      Vector4(0.0, AvatarTransform.Translation.Y, 0.0, 1.0),
      Vector4(0.0, (AvatarTransform.Translation.Y - AvatarTransform.Direction.Y), 0.0, 1.0),
    ], false);
    Mesh.SetIndexes([
      // line loop on Z = -1
      0, 1
    ]);

 
 // Line somewhere later down the code; I guessed the problem was
 // not having the correct amount of inputs to match the procedure 
 // definition above, but it still doesn't draw anything afterward

CreateMesh;
  

Even though I made sure to make sure to actually define the parameter in the function declaration, and follow examples of the game engine for doing the correct format and syntax, it still compiles fine but never actually draws anything.

Does anyone with expertise in this kind of thing know why this is?

The full project for reference download is here, as this code is only one small part of it:

Link to full project in a ZIP archive

I followed the directions of a particular example for the thing I needed, and expected it to work the same.

However, it ended up not working at all, which is why I am confused.

23
  • I think cause the Raycast Direction has a negative number for the coordinate, I should have added rather than subtracted, but either way it should have drawn something. Commented Feb 12, 2024 at 11:41
  • Silly me, I think I figured it out. Not only that, but also I didn't actually specify any parameters when I called the function later on down the code. Commented Feb 12, 2024 at 13:21
  • If that is indeed correct, I think we can lock the topic because there is no need to discuss a problem with a found solution? Commented Feb 12, 2024 at 13:21
  • Although I did find out I didn't use a function with parameters correctly and fixed that, it still doesn't draw correctly - therefore the problem is not fixed and still there. It just doesn't make any sense, given how I followed all the rest of the directions exactly - the only thing I changed was to specify that the SetVertices procedure/function will take inputs, whereas that wasn't true earlier. Commented Feb 12, 2024 at 13:25
  • 1
    Facepalm A: If you are going to tell me that there is something like too minimal, I will have to take my business elsewhere - by definiton minimal means that you have as little code as necessary to re-create the problem, because all the rest is irrelevant to the problem at hand. B: I still advocate it can be compiled if you use the project linked and paste the lines in the appropriate file specified. C: It does in fact exhibit the problem I am talking about, because I posted all the lines exactly as they were, complete with the indenting necessary and comments, to show you how to reproduce. Commented Feb 13, 2024 at 13:16

1 Answer 1

0

The most likely answer to your main question is that you didn't call "Mesh.Render(pmLines)". Possibly you just forgot it, which explains why you don't see anything.

If you are unsure how TCastleRenderUnlitMesh works, please:

The things you really have to set before rendering are:

  • Vertexes, using SetVertexes.

  • Matrix (combined projection * camera * model transformation) ModelViewProjection.

  • That's it, the rest has sensible defaults. You can just call Render.

This question is a duplicate of a question you asked on Lazarus forums: https://forum.lazarus.freepascal.org/index.php/topic,66238.0.html . I give there more details. There are even more details in the Castle Game Engine forum thread(s) where we try to help you, in https://forum.castle-engine.io/t/need-help-making-collision-with-ground-work-correctly/1025/70 .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.