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.