Render question

hello,

I’ve got a question about rendering.

I’ve created my own camera and attached it to my scene graph like this :

	PT(PerspectiveLens) pLens = new PerspectiveLens();
	pLens->set_fov(67.0f);
	float w = GameWindow()->get_display_region_3d()->get_pixel_width();
	float h = GameWindow()->get_display_region_3d()->get_pixel_height();
	float aspect_ratio = w / h;
	pLens->set_aspect_ratio(aspect_ratio);
	PT(Camera) pCamera = new Camera("BaseCamera", pLens);
	mFocusNode = Render3D().attach_new_node("FocusNode");
	mFocusNode.set_pos(0,0,0);
	mCameraNode = Render3D().attach_new_node(pCamera);
	mCameraNode.reparent_to(mFocusNode);
	GameWindow()->get_display_region_3d()->set_camera(mCameraNode);
	pCamera->set_active(true);
	mCameraNode.set_pos(100.0f,0.0f,100.0f);
	mCameraNode.look_at(mFocusNode);
	mCameraNode.show();

everything looks as it should so far.

Now I’ve attached a 3d model to the hud (render2D) like this :

	LVector3f Pos3D = LVector3f(0.0f, 0.0f, 0.0f);

	myNode = //load the 3D model

	NodePath render2D = GameWindow()->get_render_2d();

	PT(Camera) pCamera = //my camera

	LPoint2f hudPos2D;
	pCamera->get_lens()->project(pos3D, hudPos2D);

	myNode.reparent_to(render2D);

	myNode.set_pos(hudPos2D.get_x(), hudPos2D.get_y(), 0.0f);
	myNode.show();

the problem is my 3d model is displayed very streched along the x axis.

Anyone knows why that is ?

Chrys

I see you setting the aspect ratio on your render3D lens, but not for your render2D lens. (In fact, I don’t see the setup for render2D at all. Are you using the framework-provided render2D, or are you setting up your own?)

The Panda convention is for render2d to be -1…1 in both axes, regardless of the aspect ratio of the window, so anything you parent directly to render2d will be squashed unless you have a perfectly square window. But we also provide aspect2d, a child of render2d with a scale to compensate for the window shape, so that anything you parent to aspect2d will not be squashed.

David

the render2d is just the standard render2d of the framework, I havent setup any lens for it . Do I need to do that ?

No, you can certainly use the standard render2d. I only asked about setting up your own lens because I see you doing that for render3d, and I don’t know how much DIY you’re going for here.

But if you want things not to be squashed, you should use aspect2d instead of render2d, as I just explained. :slight_smile:

David