Jump to content

Recommended Posts

Posted

Hi,

I need the Angle between a Plane and the Camera:

 


Leadwerks::Vec3 V1 = mPlane->GetPosition();
Leadwerks::Vec3 V2 = camera->GetPosition();

// turn vectors into Normals
Leadwerks::Vec3 V1n = V1.Normalize();
Leadwerks::Vec3 V2n = V2.Normalize();

//the Dot Product
float dot = V1n.Dot(V2n);

//And the Angle
float angle = Leadwerks::Math::ACos(dot);

 

But the Angle is not correct.

Posted

Well V1 is not contained in mPlane so what did yiubexpect?

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Posted

This might:

float tRoty;

// Calculate angle from point A towards point B
Vec3 tv = secondEntity.GetPosition - entity->GetPosition();
tRoty = Math::ATan2(tv.x, tv.z);

Posted

The dot product ranges from -1 to 1, so I think the angle might something like this:

angle = (1.0 + a.Dot(B)) * 90.0

 

That way -1 would give an angle of zero and +1 would give an angle of 180.

 

You might have to flip the sign. +/-

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

Hi,

I need the Angle between a Plane and the Camera:

 


Leadwerks::Vec3 V1 = mPlane->GetPosition();
Leadwerks::Vec3 V2 = camera->GetPosition();

// turn vectors into Normals
Leadwerks::Vec3 V1n = V1.Normalize();
Leadwerks::Vec3 V2n = V2.Normalize();

//the Dot Product
float dot = V1n.Dot(V2n);

//And the Angle
float angle = Leadwerks::Math::ACos(dot);

 

But the Angle is not correct.

 

The angle is correct, you are just feeding it the wrong values for what I assume you want to do.

This is the angle you are actually calculating:

https://docs.google.com/file/d/0B3jPhxJap2Y3QUN2aTBldWZMZGc/

Posted

That video explains it quite nicely, as you can see, the plane is the point from which everything is calculated.

 

One correction about the dot product

a*b=abs(a)*abs(b )*cos(phi) thus acos(a*b/(abs(a)*abs(b )))=phi

(Watch for divide by zero situations!)

which is essentailly what you do already but with the wrong values.

 

As the video shows, you need the normal of that plane and the distance plane to camera.

 

That nebula effect is really cool btw.

Posted

That's a good technique for volumetric spotlight effects, too. Source engine uses it for headlights and stuff like that.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

As a side note to the OP, a 'normalized' vector is not the same thing as the normal vector.

 

Vec3:Normalize returns a vector which is normalized (brought back to values of 1).

Vec3:Cross returns the cross product aka the normal vector.

Posted
Vec3:Normalize returns a vector which is normalized (brought back to length of 1).

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Posted

Ok, thanks all for help.

 

I think I have the solution:

 

//Get the Plane Normal
Surface* surface = mPlane->GetSurface(0);
Leadwerks::Vec3 V1 = surface->GetVertexNormal(1);
//Get the Differenz between Camera and Plane
Leadwerks::Vec3 V2 = camera->GetPosition() - mPlane->GetPosition();

//Normalize the Vectors
V1 = V1.Normalize();
V2 = V2.Normalize();

//The Dot Product
float dot = V1.Dot(V2);

//ABS
float dotAbsolute = Leadwerks::Math::Abs(dot);

cout << dotAbsolute << endl;

mPlane->SetColor(1, 1, 1, dotAbsolute);

  • Upvote 2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...