Skip to main content

Drawing coordinates system axes in corner of screen

Drawing coordinates system axes in corner of screen


void CDEMView::DrawSomeBox()
{
	// Define the needed matrices - object world, view and project 
	D3DXMATRIX matObjectWorld;
        D3DXMatrixIdentity (&matObjectWorld);	// object world matrix
	D3DXMATRIX matView;				
        D3DXMatrixIdentity (&matView);		// view matrix
	D3DXMATRIX matProjection;	
        D3DXMatrixIdentity (&matProjection);	// projection matrix
	
	// Get the needed matrices
	_device->GetTransform(D3DTS_VIEW, &matView);
	_device->GetTransform(D3DTS_PROJECTION, &matProjection);

	// Get the viewport
	D3DVIEWPORT9 viewport;
	_device->GetViewport(&viewport);

	// Get the center point of the object		
	D3DXVECTOR3* p_centerPoint = BoxCenterVector; // this is from an external variable

	// Get the point on the creen that is the screen projection of the object
	D3DXVECTOR3 projectPoint;
	D3DXVec3Project(&projectPoint, p_centerPoint ,&viewport, &matProjection, &matView, &matObjectWorld);

	// choose the screen point where the object is to be drawn, relative to the Viewport's dimensions
	D3DXVECTOR3 screenPoint;
	screenPoint.x = 0.1*viewport.Width;	// x position (horizontal) is 10% of the width of the screen (0% is left, 100% is right)
	screenPoint.y = 0.9*viewport.Height;	// y position (vertical) is 90% of the height of the screen (0% is top, 100% is bottom)
	screenPoint.z = projectPoint.z;		// 1-projectPoint.z*60/(-zoom);

	//transform the screen position to a world position
	D3DXVECTOR3 worldPoint;
	D3DXVec3Unproject( &worldPoint, &screenPoint, &viewport, &matProjection, &matView, &matObjectWorld );

	// now define how much to translate the box in order to get it to the point we want it to be (WorldPoint)
	float transX, transY, transZ;
	transX = worldPoint.x;
	transY = worldPoint.y;
	transZ = worldPoint.z;
	
	// define a mesh to store the object into and create the object
	ID3DXMesh* _SomeBox;
	float boxSize = 2.0f;
	D3DXCreateBox(_device,boxSize,boxSize,boxSize,&_SomeBox,NULL);

	// define a material and set its color
	D3DMATERIAL9 mat;

	// Set the RGBA for diffuse reflection.
	mat.Diffuse.r = 255;
	mat.Diffuse.g = 0;
	mat.Diffuse.b = 0;
	mat.Diffuse.a = 0.5;

	_device->SetMaterial(&mat);
	_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); // D3DFILL_SOLID

	// apply the translation matrix
	D3DXMatrixTranslation(&matObjectWorld, transX, transY, transZ);
	_device->SetTransform(D3DTS_WORLD, &matObjectWorld);

	// draw the object
	_SomeBox->DrawSubset(0);
	// release the mesh
	_SomeBox->Release();

	// some debugging variables
	debug1 = transX;
	debug2 = transY;
	debug3 = transZ;
	debug4 = boxSize;
	//debug5 = scaleFactor;
	manole = 0;
}

Comments

Popular posts from this blog

Create a socket for HTTP for web page upload and download

Create a socket for HTTP for web page upload and download. Aim: To write a java program for socket for HTTP for web page upload and download . Algorithm 1.Start the program. 2.Get the frame size from the user 3.To create the frame based on the user request. 4.To send frames to server from the client side. 5.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client. 6.Stop the program Program : Client import javax.swing.*; import java.net.*; import java.awt.image.*; import javax.imageio.*; import java.io.*; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Client{ public static void main(String args[]) throws Exception{ Socket soc; BufferedImage img = null; soc=new Socket("localhost",4000); System.out.println("Client is running. ");  try { System.out.println("Reading image from disk. "); im...

Write a code simulating ARP /RARP protocols

   Write a code simulating ARP /RARP protocols . Aim:        To write a java program for simulating ARP/RARP protocols ALGORITHM: server 1. Create a server socket and bind it to port. 2. Listen for new connection and when a connection arrives, accept it. 3. Send server ‟ s date and time to the client. 4. Read client ‟ s IP address sent by the client. 5. Display the client details. 6. Repeat steps 2-5 until the server is terminated. 7. Close all streams. 8. Close the server socket. 9. Stop. Client 1. Create a client socket and connect it to the server ‟ s port number. 2. Retrieve its own IP address using built-in function. 3. Send its address to the server. 4. Display the date & time sent by the server. 5. Close the input and output streams. 6. Close the client socket. 7. Stop. Program Program for Address Resolutuion Protocol (ARP) using TCP Client: import java.io.*; import java.net.*; impor...

Write program to find ε – closure of all states of any given NFA with ε transition.

 Write program to find ε – closure of all states of any given NFA with ε transition. Agenda 1.Program 2.Input/Output 1.Program #include <stdio.h> #include <string.h> char  result[ 20 ][ 20 ], copy[ 3 ], states[ 20 ][ 20 ]; void  add_state( char  a[ 3 ],  int  i) {   strcpy(result[i], a); } void  display( int  n) {    int  k =  0 ;   printf( "nnn Epsilon closure of %s = { " , copy);    while  (k < n) {     printf( " %s" , result[k]);     k++;   }   printf( " } nnn" ); } int  main() {   FILE * INPUT;   INPUT = fopen( "input.dat" ,  "r" );    char  state[ 3 ];    int  end, i =  0 , n, k =  0 ;  ...