|
frank_, Newbie
Posted: 30 July 2012 02:25 PM Total Posts: 12
[ # 16 ]
yup, I have it in my frame loop:
This method is called on enter frame
protected function handleRender(e:Event):void{ this.adjustScale(); if(move){ controller.panAngle = .3 * (stage.mouseX - lastMouseX) + lastPanlAngel; controller.tiltAngle = .3 * (stage.mouseY - lastMouseY) + lastTiltAngle; //trace(controller.panAngle + " " + controller.tiltAngle); } pointLight.position = cam.position; view.render(); }
|
Richard Olsson, Administrator
Posted: 30 July 2012 02:32 PM Total Posts: 1192
[ # 17 ]
And what does adjustScale() do? Please do not leave any information out, that could be of importance, when asking for help like this.
Note that when I said you have to redo the projection test every frame, to recalculate the scale factor, I was referring to the preparation with two project() calls, that results in a scale factor being calculated. Is that what you’re doing in adjustScale()?
|
frank_, Newbie
Posted: 30 July 2012 02:36 PM Total Posts: 12
[ # 18 ]
Sorry, posted this earlier in the thread:
Adjust scale loops through my vector of OC3D’s and rescales
private function adjustScale():void{ for(var i:int = 0 ; i < floorNumbers.length ; i++){ var scale:Number = (floorNumbers[i].z - view.camera.z) * returnScaleDist(); floorNumbers[i].scaleX = scale; floorNumbers[i].scaleY = scale; floorNumbers[i].scaleZ = scale; } } private function returnScaleDist():Number{ var v0:Vector3D = view.camera.project(new Vector3D(0, 1, 0)); var v1:Vector3D = view.camera.project(new Vector3D(0, 1, 1000)); return (v1.y / v0.y) / 1000; }
These are the objects that are being put into the container
private function returnFloorNum(aInt:int):ObjectContainer3D{ var g:ObjectC ObjectContainer3D(); var text:IBitmapDrawable = ExtAssets.returnNumber(aInt); var bmd:BitmapData = new BitmapData(64, 64, true, 0x000000); bmd.draw(text, null, null, null, null, true); var bmt:BitmapTexture = new BitmapTexture(bmd); var textMat:TextureMaterial = new TextureMaterial(bmt); //front face var pFront:PlaneGeometry = new PlaneGeometry(64, 64); var mFront:Mesh = new Mesh(pFront, textMat); //pTest.doubleSided = true; mFront.moveLeft(500); mFront.moveUp(((aInt * 105) + 2) - 350); mFront.rotati mFront.rotati mFront.rotati g.addChild(mFront); //back face var pBack:PlaneGeometry = new PlaneGeometry(64, 64); var mBack:Mesh = new Mesh(pBack, textMat); mBack.moveLeft(500); mBack.moveUp(((aInt * 105) + 2) - 350); mBack.rotati mBack.rotati mBack.rotati g.addChild(mBack); return g; }
|
Richard Olsson, Administrator
Posted: 31 July 2012 08:19 AM Total Posts: 1192
[ # 19 ]
Aha, I see now. You seem to be making the same mistake that the OP made, in that you’re using the Z positions of the objects to calculate the “distance”, but unless your camera is looking straight on from the front the Z delta will not actually be the same as the distance.
Use the scenePosition property of your camera and your object, and the Vector3D.distance() function to calculate the distance instead of just subtracting their Z values.
|
frank_, Newbie
Posted: 31 July 2012 02:32 PM Total Posts: 12
[ # 20 ]
Thanks for the reply, I’ve changed the z subtraction to this:
var scale:Number = Vector3D.distance(cam.scenePosition, floorNumbers[i].scenePosition) * returnScaleDist();
But I still seem to be getting the same result.
The scale of my items changed depending on the camera rotation. They do not scale when I change the camera FOV
This is how I’m changing my FOV:
protected function handleZoom(e:MouseEvent):void{ var l:PerspectiveLens = view.camera.lens as PerspectiveLens; l.fieldOfView -= e.delta;
}
|
Richard Olsson, Administrator
Posted: 01 August 2012 07:20 AM Total Posts: 1192
[ # 21 ]
Ah, wait a second. You’re still using the (0,1,0) and (0,1,1000) vectors to calculate the projection difference.
Now, what that step is meant to do is to take two points that are both in the direct line of sight of the camera, but at different distances from it, and figure out how much they differ once projected. If you have moved the camera, those projections won’t be enough anymore.
Can you verify that changing FOV works if you do not move your camera from it’s default (0,0,-1000) position?
If so, you will need to transform the two points into camera space first. The points should then be (0,1,1000) and (0,1,2000), and you can transform them using the transformVector() method on Camera3D.sceneTransform before doing the project().
// 1. Create v0 and v1 as usual // 2. Transform them into camera space: v0 = myCamera.sceneTransform.transformVector(v0); v1 = myCamera.sceneTransform.transformVector(v1);
// 3. Perform project() procedure as usual
Now the code is actually starting to get a little bit complex, and what was intended as a quick hack to avoid having to do the actual projection math might actually no longer be motivated.
Let me know if it doesn’t work out and we can look at using a more lean but also more mathematical approach.
|
frank_, Newbie
Posted: 01 August 2012 01:33 PM Total Posts: 12
[ # 22 ]
Thanks for helping out with this, I really appreciate it.
As for moving the camera from its initial position:
I don’t think I’m explicitly doing that, unless I’m completely ignorant of how the HoverController works. Any view operations are done on the controller instead of the camera.
Here is a bit of that code:
setting up the cam and controller:
cam = new Camera3D(); controller = new HoverController(cam, null, 0, 360, 1500, -90, 90, NaN, NaN, 8, 1, false); controller.wrapPanAngle = true; view = new View3D(); view.camera = cam;
And this is how I rotate the camera based off the mouse position, inside my frame loop
if(move){ controller.panAngle = .3 * (stage.mouseX - lastMouseX) + lastPanlAngel; controller.tiltAngle = .3 * (stage.mouseY - lastMouseY) + lastTiltAngle; //trace(controller.panAngle + " " + controller.tiltAngle); }
I’ve changed my returnScaleDist method to include the transform but it doesn’t seem to be working yet. In fact the scale is always near or at 0 depending on controller rotation:
private function returnScaleDist():Number{ var v0:Vector3D = new Vector3D(0, 1, 0); var v1:Vector3D = new Vector3D(0, 1, 1000); v0 = cam.sceneTransform.transformVector(v0); v1 = cam.sceneTransform.transformVector(v1); v0 = cam.project(v0); v1 = cam.project(v1); return (v1.y / v0.y) / 1000; }
|
Richard Olsson, Administrator
Posted: 01 August 2012 02:13 PM Total Posts: 1192
[ # 23 ]
HoverController does indeed move the camera, or your point of view would be static. So whether you move the camera directly or let the HoverController do it doesn’t matter.
Note that you need to change the vectors to (0,1,1000) and (0,1,2000) like I mentioned in my previous reply. If you do that in your returnScaleDist() function things should hopefully work better. The reason for this is that what you want is to have one point 1000 units away from the camera, and another point 2000 units away, and before when the camera (in it’s default position) was at (0,0,-1000), the (0,1,0) vector was actually 1000 units away from the camera.
Now we are transforming vectors into the cameras space, so (0,0,0) is the position where the camera is, and thus a point 1000 units away from it is (0,0,1000). Therefor, the two points must have Z values at 1000 and 2000 respectively, and that’s why they should be at (0,1,1000) and (0,1,2000).
Hope this helps!
|