Positioning of Camera

I am having trouble positioning my cameras. I have a NodePath object which represents a model at (0,0,0) and a camera at (0,20,0). But the camera still looks at the model even when the camera is 20 pixels ahead of the model on the Y-axis. How does this work?

Well, first, let me clarify your units: in 3-D, the units are certainly not pixels. They might be anything you say they are–feet, centimeters, miles, it doesn’t matter, as long as you’re consistent–but the units are spatial distance, not screen distance.

Still, it’s generally true that the camera looks forward along the +Y axis, and things that are behind the camera on the Y axis are not visible. So, if your camera is at (0, 20, 0), and your model is at (0, 0, 0) (and smaller than 20 units), and the camera is not rotated, then the model would certainly be invisible. If the model is visible, then you must be mistaken about one of the above.

David

//the camera

NodePath cam2 = window->get_camera(0);
		cam2.set_pos(0,40,1.5);
		cam2.set_hpr(0,0,90);

//the display region
DisplayRegion *dr2 = window->get_graphics_window()->make_display_region(0.33,0.66,0,1);
		dr2->set_camera(cam2);
		dr2->set_active(true);
//the model
NodePath environ = window->load_model(framework.get_models(),"UVMapONLY-AW-v1");
	
environ.reparent_to(window->get_render());	
		environ.set_scale(3,3,3);
		environ.set_pos(0,0,0);
		environ.set_hpr(0,0,0);

This is my current placement of objects and the model is visible

Did you call window->enable_trackball()? If you did, then the trackball is in charge of the camera’s position, and will override whatever you set it to. If you intend to position the camera yourself, you should not make this call.

Also, I have no idea how your model is created. Are you sure that your model is centered at (0,0,0)? How large is it?

David

Oh, also, you should use window->get_camera_group() instead of window->get_camera(0). The NodePath returned by get_camera_group() is the parent node of all of the cameras, and is the node that you are generally intended to manipulate in order to reposition one or more cameras.

If you use get_camera(0) instead, you are using the child node, which is OK but then you should reparent that node directly to render, so that it does not inherit any unwanted transforms from its parent node.

David

Hey,
The enable_trackball was messing things around. Now the camera makes sense. And when I use get_camera_group(), my program crashes. But doesn’t crash when i use get_camera(0). Also I need 3 cameras to look at one model and create 3 different display regions, which I got working. Also have I made the other cameras using make_camera(), I donno if that’s wats affecting the get_camera_group() function. Thanks for the help.