Anonymous - 2022-09-05

Hello,

Back in the ms-dos days I knew there was a trick to "hide/skip" over triangles or polygons that were facing away from the camera or simply put 0 or something.

So this article presents the basic formula:

https://stackoverflow.com/questions/28794883/back-face-culling-for-linestrips

So at the bottom it states to multiple some object/face/poiint/line/polygon normal with a camera direction/normal or something.

Then compute dot product and check if it's not zero, if so include it in rendering otherwise skip.

At least that's how I interpret or perhaps I am lazy. Normally the normal would be computed based on the orientation of triangles/polygons/clockwise and such. However for points on a sphere or lines on a sphere the normal is already know, it's simply the coordinate from the center of the object. The object is at zero, zero zero so I believe, so all that is necessary is to normalize the point on the sphere, so all x,y,z are within 0..1 and then dot product multiple it with camera direction vector which is also normalized.

The idea of the code below is to pre-compute points and store them in WorldPoints (not shown).

and then copy the points from WorldPoints to WorldPointsRender during the onProgress event of the cadencer.

So the idea here is to only include points on the sphere that are pointing towards the camera.

It seems to work somewhat, but when the camera rotates, it seems like the normal of the camera doesn't change. How to fix this code/idea ?

procedure TForm1.GLPointsWorldRenderProgress(Sender: TObject; const DeltaTime,
NewTime: Double);
var
vCount : integer;
vIndex : integer;

vPoint : TVector3f;
vPointVector : TVector3f;
vCameraVector : TVector3f;

begin
GLPointsWorldRender.Positions.Clear;

vCount := GLPointsWorld.Positions.Count;
for vIndex := 0 to vCount-1 do
begin
    // get point normal and normalize
    vPoint := GLPointsWorld.Positions[vIndex];

    vPointVector := vPoint;
    NormalizeVector(vPointVector);

    // get camera normal and normalize
    vCameraVector.X := GLCamera.Direction.X;
    vCameraVector.Y := GLCamera.Direction.Y;
    vCameraVector.Z := GLCamera.Direction.Z;

    NormalizeVector(vCameraVector);

    if VectorDotProduct( vPointVector, vCameraVector ) > 0 then
    begin
        GLPointsWorldRender.Positions.Add( vPoint );
    end;
end;

end;