Published © LGPL

3D Projection

A 3D projection tutorial.

AdvancedProtip2,542
3D Projection

Things used in this project

Hardware components

Arduino Micro
Arduino Micro
×1
Seeed Studio TFT
×1
Texas Instruments 74HC595
×1

Story

Read more

Schematics

basic schematic

Code

ATmega32u4_3DProjection

Arduino
/*
*	Author		: Zavala Ortiz Vicente Arturo.
*	language	: .ino
*	Date		: 4/25/2013 2:51:45 PM
*	Name		: ATmega32u4_3DProjection.ino
*	Description : 3D projection
*/

#include <avr/io.h>
#include <avr/pgmspace.h>

#include "TFT.h"
#include "3D_Math.h"

void init_prespective(double Psi, double Theta, double Phi, double rotPsi, double rotTheta, double rotPhi);
void cube_3D();

#define KEYBOARD_MASK										0xF0

UBYTE SHAPE			= 20;

VECTOR_3D pts3D;
double Psi, Theta, Phi, rotPsi, rotTheta, rotPhi;

volatile uint8_t INT_BITS;
uint8_t option;

void setup()
{
	/* add setup code here */
	Tft.init();
	
	3D.setViewport(-4, 4, -3, 3, 0, 200, 50, 250);
	init_prespective(Psi, Theta, Phi, rotPsi, rotTheta, rotPhi);
	
	Psi			= 75;
	Theta		= 0;
	Phi			= 165;
	rotPsi		= Psi;
	rotTheta	= Theta;
	rotPhi		= Phi;

	cli();	
	// Enable external pin interrupts
	set_bit_port(PCICR, PCIE0);
	set_bit_port(PCMSK0, PCINT4);
	set_bit_port(PCMSK0, PCINT5);
	set_bit_port(PCMSK0, PCINT6);
	sei();
}

void loop()
{
	/* add main program code here */	
	if(INT_BITS != 0)
	{
		Tft.clrscr();
				
		switch(option)
		{			
			case 0x10:
				if((Psi += 25) > 360) Psi = 0.0;				
			break;

			case 0x20:		
				if((Theta += 25) > 360) Theta = 0.0;
			break;

			case 0x40:		
				if((Phi += 25) > 360) Phi = 0.0;				
			break;
		}
		
		init_prespective(Psi, Theta, Phi, rotPsi, rotTheta, rotPhi);
		
		switch(SHAPE)
		{
			case 10 :
			break;
			
			case 20 :
				cube_3D();					// Cube
			break;
			
			case 30 :
			break;
			
			case 40 :
			break;
		}
	}
}

ISR(PCINT0_vect)
{
	if((INT_BITS = (PINB & KEYBOARD_MASK))) {	
		option = INT_BITS;
		_delay_ms(5);			// Switch debounce
	}
}

Credits

Comments