Schoppy0384 Posted September 5, 2014 Share Posted September 5, 2014 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. Quote Link to comment Share on other sites More sharing options...
Guppy Posted September 5, 2014 Share Posted September 5, 2014 Well V1 is not contained in mPlane so what did yiubexpect? Quote System: Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k Link to comment Share on other sites More sharing options...
shadmar Posted September 5, 2014 Share Posted September 5, 2014 mPlane and camera vectors are just positions which you have normalized, and it doesn't make any sense. What are you trying to achieve? Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Vulcan Posted September 5, 2014 Share Posted September 5, 2014 Try using Math:Atan2, if I remember correctly you get the angle between them. Quote Link to comment Share on other sites More sharing options...
Vulcan Posted September 5, 2014 Share Posted September 5, 2014 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); Quote Link to comment Share on other sites More sharing options...
Josh Posted September 5, 2014 Share Posted September 5, 2014 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. +/- Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
DerRidda Posted September 5, 2014 Share Posted September 5, 2014 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/ Quote Link to comment Share on other sites More sharing options...
Schoppy0384 Posted September 5, 2014 Author Share Posted September 5, 2014 Ok, i need exactly this effect: 1 Quote Link to comment Share on other sites More sharing options...
Guppy Posted September 5, 2014 Share Posted September 5, 2014 Point distance to plane: 1 Quote System: Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k Link to comment Share on other sites More sharing options...
DerRidda Posted September 5, 2014 Share Posted September 5, 2014 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted September 5, 2014 Share Posted September 5, 2014 That's a good technique for volumetric spotlight effects, too. Source engine uses it for headlights and stuff like that. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 5, 2014 Share Posted September 5, 2014 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. Quote Link to comment Share on other sites More sharing options...
Guppy Posted September 6, 2014 Share Posted September 6, 2014 Vec3:Normalize returns a vector which is normalized (brought back to length of 1). Quote System: Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k Link to comment Share on other sites More sharing options...
Schoppy0384 Posted September 7, 2014 Author Share Posted September 7, 2014 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); 2 Quote Link to comment Share on other sites More sharing options...
Schoppy0384 Posted September 8, 2014 Author Share Posted September 8, 2014 Hi, another problem. After rotating the Plane, the Effect don't work. Are the VertexNormal are not rotating too? Quote Link to comment Share on other sites More sharing options...
Ma-Shell Posted September 8, 2014 Share Posted September 8, 2014 I would guess, they are in object space. In that case you would have to multiply them by the transformation matrix of your entity. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.