Dbof

Member
  • Content count

    5
  • Joined

  • Last visited

Community Reputation

105 Neutral

About Dbof

  • Rank
    Newbie
  1. OMG...figured out by myself. The formula I was using for the lookAt was wrong. void dbCamera::lookAt(dbVector3 target) { camUp = dbVector3(0.f, 1.f, 0.f); // this is what was missing... // from: http://msdn.microsoft.com/en-us/library/windows/desktop/bb281710%28v=vs.85%29.aspx camDirection = dbVector3Norm(target - camPos); camRight = dbVector3Norm(dbVector3Cross(camUp, camDirection)); camUp = dbVector3Norm( dbVector3Cross(camDirection, camRight) ); } I confused the camera up-vector with the world up-vector...
  2. I'm trying to implement rotation functions for a camera. Here is some code: void dbCamera::rotateAroundXYZ(dbVector3 position, float angle){ // from: http://www.gamedev.net/topic/183293-camera-rotating-a-vector-around-an-arbitrary-axis/ dbVector3 vNewView; dbVector3 vView = camPos - camDirection; float cosTheta = cos(angle); float sinTheta = sin(angle); // x position of the new rotated point vNewView.x = (cosTheta + (1 - cosTheta) * position.x * position.x) * vView.x; vNewView.x += ((1 - cosTheta) * position.x * position.y - position.z * sinTheta) * position.y; vNewView.x += ((1 - cosTheta) * position.x * position.z + position.y * sinTheta) * vView.z; // y position of the new rotated point vNewView.y = ((1 - cosTheta) * position.x * position.y + position.z * sinTheta) * vView.x; vNewView.y += (cosTheta + (1 - cosTheta) * position.y * position.y) * vView.y; vNewView.y += ((1 - cosTheta) * position.y * position.z - position.x * sinTheta) * vView.z; // z position of the new rotated point vNewView.z = ((1 - cosTheta) * position.x * position.z - position.y * sinTheta) * vView.x; vNewView.z += ((1 - cosTheta) * position.y * position.z + position.x * sinTheta) * vView.y; vNewView.z += (cosTheta + (1 - cosTheta) * position.z * position.z) * vView.z; camPos = camDirection + vNewView;} This seems to work for now. My problem now is the looAt function: void dbCamera::lookAt(dbVector3 target){ // from: http://msdn.microsoft.com/en-us/library/windows/desktop/bb281710%28v=vs.85%29.aspx camDirection = dbVector3Norm(target - camPos); camRight = dbVector3Norm(dbVector3Cross(camUp, camDirection)); camUp = dbVector3Norm( dbVector3Cross(camDirection, camRight) );} The function names should be self-explanatory. The bug acts when I try to rotate around an axis while looking at a point on the axis. What I want to achieve is a camera which can rotate around an object and always looks at it (like a 3rd person camera). What the camera does is...well, rotate around itself during the rotation. http://youtu.be/CKud5uKotxE Uploaded a short video of the rotation. The first rotation is on the same Y-position of the car. The second one the camera goes up and it all fucks up. Any idea what may cause this problem? Thanks in advance!
  3. Lighting issue

    [quote name='undead' timestamp='1314780637' post='4855798'] [quote name='Dbof' timestamp='1314778699' post='4855792'] And this is my problem. I do not want the light to affect the cube if it is outside of it. As you can see, it is very unrealistic that the side walls are visible when the light rays are not supposed to light them. [/quote] If the normals are flipped (they point on the inside) then from what I see the results are ok. Kidsnapper4 clearly shows the top isn't affected because the normals are flipped but the lit face normals are actually pointing at the light. You need a shadowing system or if you need a quick trick just check if the light is outside the cube. When it's outside just set one parameter of your light equation to zero. [/quote] Oh, this means when the normals are at an angle of less than 90 degrees from the light, they are automaticly lit? Probably did not consider it, thank you. I am going to check what I can do against.
  4. Lighting issue

    Thanks god someone answered. Ok, I really thought it was clear. Once again. I want to create a scene with a cube. This cube should not be visible/lit. Imagine a military bunker which is only lit from the inside and has thick walls, so the light can't be perceived from the outside. The range is not important for now, everything should be affected by light for now. I thought by inverting the normals of my cube, so their direction go into the cube, It would be possible to light the cube from the inside only. This is the cube (which has a little window): [url="http://dbof.redio.de/screen/kidsnapper2.jpg"]http://dbof.redio.de...kidsnapper2.jpg[/url] The sphere above the cube is the (only) light source (point light) [url="http://dbof.redio.de/screen/kidsnapper3.jpg"]http://dbof.redio.de...kidsnapper3.jpg[/url] When the light is near the top, but outside of the cube, the top is dark, while the rest is lit, which is very unrealistic, because there should not be any light shining on the sides: [url="http://dbof.redio.de/screen/kidsnapper4.jpg"]http://dbof.redio.de...kidsnapper4.jpg[/url] When the light is moved near another wall, which was theoretically not hit by the light, it becomes dark: [url="http://dbof.redio.de/screen/kidsnapper6.jpg"]http://dbof.redio.de...kidsnapper6.jpg[/url] And this is my problem. I do not want the light to affect the cube if it is outside of it. As you can see, it is very unrealistic that the side walls are visible when the light rays are not supposed to light them. Now any ideas? I hope I get a faster answer this time
  5. Hello! I'm pretty new to this forum and I already have a few questions to ask. I'm trying to light a scene correctly. My attempt is to have a closed room (cube) and light it from the inside, so you have to put the camera inside the room to see something. Before I realized I had to flip the normals, I could only light the room from the outside. The problem I'm encountering now can be seen in this picture: [url="http://i.min.us/ib0xXBIBEvY3LV.jpg"]http://i.min.us/ib0xXBIBEvY3LV.jpg[/url] The light in the middle of the screenshot (which is a sphere) contains a point light: [code]light.Type = D3DLIGHT_POINT; light.Position = pos; light.Range = 1000.f; light.Diffuse = Diffuse; [i]//White[/i] light.Specular = Specular; [i]//White[/i] light.Ambient = Ambient; [i]//Really dark (0.05, 0.05, 0.05)[/i] light.Attenuation0 = 0.f; light.Attenuation1 = 0.01f; light.Attenuation2 = 0.f;[/code] I created the cube with Blender and flipped the normals, so that the walls are lit from the inside of the cube. As you can see, when the light is outside of the cube, the cube's walls, which are not in the light's shining range, are lit. Any idea how to fix this issue? Hope I was clear enough.. Thank you in advance!