Wrong normal for triangles

I am making a 3D game using SFML. I want to use normals to check if the triangle need to be draw in a terrain (triangle) mesh.
Here is my code:

vec3d line1, line2, normal;
line1.x = terrain.tris[i].p.x - terrain.tris[i].p.x;
line1.y = terrain.tris[i].p.y - terrain.tris[i].p.y;
line1.z = terrain.tris[i].p.z - terrain.tris[i].p.z;

line2.x = terrain.tris[i].p.x - terrain.tris[i].p.x;
line2.y = terrain.tris[i].p.y - terrain.tris[i].p.y;
line2.z = terrain.tris[i].p.z - terrain.tris[i].p.z;

normal.x = line1.y * line2.z - line1.z * line2.y;
normal.y = line1.z * line2.x - line1.x * line2.z;
normal.z = line1.x * line2.y - line1.y * line2.x;
vec3d vCameraRay = Vector_Sub(terrain.tris[i].p, cam.pos);
if (Vector_DotProduct(normal, vCameraRay) < 0.0f){
do_something();
}

Vector_DotProduct:

float Vector_DotProduct(vec3d& v1, vec3d& v2) {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}

Vector_sub:

vec3d Vector_Sub(vec3d& v1, vec3d& v2) {
return { v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
}

And the vec3d is just a struct that contains

float x, y, z;

But whenever I run the program, I always get this
problem
I am not sure if this is because of the way I produce the triangle grid, or something else, so I am going to put all the things that might matter here:
The code for producing triangle grid:

for (int i = 0; i < 2; i++) {
for (int y = 0; y < wds; y++) {
for (int x = 0; x < wds; x++) {
if (x + 1 < wds && y + 1 < wds) {
vec3d point;
switch (i) {
case 0:
point = { (float)(y + 1) * scl + p.x, height * h[y + 1][x + 1], (float)(x + 1) * scl + p.z };
point = { (float)y * scl + p.x, height * h[y][x], (float)x * scl + p.z };
point = { (float)y * scl + p.x, height * h[y][x + 1], (float)(x + 1) * scl + p.z };
break;
case 1:
point = { (float)(y + 1) * scl + p.x, height * h[y + 1][x + 1], (float)(x + 1) * scl + p.z };
point = { (float)y * scl + p.x, height * h[y][x], (float)x * scl + p.z };
point = { (float)(y + 1) * scl + p.x, height * h[y + 1][x], (float)x * scl + p.z };
break;
};
triangle out = { point, point, point };
tris.push_back(out);
}
}
}
}

The wds is for the size of the grid(side length), the scl is the size of per grid, the h is the height map(two dimentions), and p is the position of the upper left corner.

My 3D point to camera point code:

float mx = p.x - pos.x;
float my = p.y - pos.y;
float mz = p.z - pos.z;
float dx = cos(rot.y) * (sin(rot.z) * my + cos(rot.z) * mx) - sin(rot.y) * mz;
float dy = sin(rot.x) * (cos(rot.y) * mz + sin(rot.y) * (sin(rot.z) * my + cos(rot.z) * mx)) + cos(rot.x) * (cos(rot.z) * my + sin(rot.z) * mx);
float dz = cos(rot.x) * (cos(rot.y) * mz + sin(rot.y) * (sin(rot.z) * my + cos(rot.z) * mx)) - sin(rot.x) * (cos(rot.z) * my + sin(rot.z) * mx);
return { dx, dy, dz };

The rot is the rotation of the camera, p is the position of the camera, and the pos is the 3D point I want to transfer to camera point.
I have been working on this problem for almost a week, but nothing seems to work.
It will be a lot of help if you guys can find the problem. Thanks in advance!

Source: Windows Questions C++