Question Planet Rendering in D3D9Client

dumbo2007

Crazy about real time sims
Joined
Nov 29, 2009
Messages
675
Reaction score
0
Points
0
Location
India
Hi,

I am trying to understand how planets are rendered in the D3D9 client code. It seems that all co-ordinates are camera centric.

There is a call to vObject::Update() which seems to get all the distances wrt the global camera position. The distance of the planet from the camera is in cdist:

From http://d3d9client.codeplex.com/SourceControl/latest#trunk/Orbitersdk/D3D9Client/VObject.cpp

Code:
	MATRIX3 grot;
	oapiGetRotationMatrix(hObj, &grot);
	oapiGetGlobalPos(hObj, &cpos);
	cpos -= scn->GetCameraGPos();

	// object positions are relative to camera

	cdist = length(cpos);

	// camera distance
	D3DMAT_SetInvRotation(&mWorld, &grot);
	D3DMAT_SetTranslation(&mWorld, &cpos);

Why is D3DMAT_SetInvRotation(&mWorld, &grot) used ? Shouldnt the rotation thats put into the world matrix be wrt the camera as the world matrix itself seems to be based on camera distances ?

Also since the world matrix seems to have all co-ordinates wrt the camera, I am guessing that no multiplication is needed with a view matrix ?

Usually there is a modeling matrix and a view matrix and the object co-ordinates in world space are multiplied with each in that order.

But is there a view matrix needed here ?
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,666
Reaction score
795
Points
128
The camera is in the origin and the world moves around the camera, however, the world does not rotate. The camera is rotated. So, there is a view matrix that's passed to the shaders directly.

The code that you have quoted contains a code that builds an object's world matrix relative to the camera. D3DMAT_SetInvRotation() will set object's rotation around it's own local axes not around the camera.
 
Top