[DEV] real display of a scene with real perspective

This commit is contained in:
Edouard DUPIN 2012-12-19 00:47:02 +01:00
parent 10f7131b62
commit cc07a77377
6 changed files with 31 additions and 24 deletions

2
external/etk vendored

@ -1 +1 @@
Subproject commit e3890a6c1471e393ba39cc431e3d1f62de0280b8
Subproject commit 5e87dea87f22b06103c5ff3f8087f28fcb4ae50c

View File

@ -19,7 +19,8 @@ void game::Camera::Update(void)
m_matrix.Rotate(vec3(1,0,0), m_angles.x );
m_matrix.Rotate(vec3(0,1,0), m_angles.y );
m_matrix.Rotate(vec3(0,0,1), m_angles.z );
m_matrix.Translate(m_position);
vec3 tmpp = m_position * -1;
m_matrix.Translate(tmpp);
EWOL_DEBUG("camera: pos=" << m_position << " angle=" << m_angles);
}

View File

@ -32,7 +32,7 @@ namespace game
* @param[in] pos Position of the camera.
* @param[in] angles Rotations angles of the camera
*/
Camera(vec3 pos=vec3(0,0,1), vec3 angles=vec3(0,0,0));/**
Camera(vec3 pos=vec3(0,0,2), vec3 angles=vec3(0,0,0));/**
* @brief Set the position of the camera.
* @param[in] pos Position of the camera.
*/

View File

@ -30,9 +30,8 @@ game::Element::Element(etk::UString meshResource) :
}
uniqueId++;
Scale(vec3(100,100,100) );
//m_property.Rotate(m_property.m_angle, rotx);
//Translate(vec3(0.01,0.0,0.0));
//Scale(vec3(100,100,100) );
//Translate(vec3(0.0,0.0,-10.0));
}
game::Element::~Element(void)
@ -89,8 +88,11 @@ void game::Element::ProcessPosition(float delta)
vec3 m_speed0(m_speed);
vec3 curentAcceleration(m_gravityForce + m_userAcceleration);
m_speed += curentAcceleration*delta;
m_position += m_speed0*delta + curentAcceleration*delta*delta/2.0f ;
m_matrixNeedUpdate = true;
//EWOL_DEBUG("modify m_position=" << m_position << "m m_speed=" << m_speed << "m/s m_gravityForce=" << m_gravityForce << "+" << m_userAcceleration << "m/s2");
vec3 tmpPos = m_position +m_speed0*delta + curentAcceleration*delta*delta/2.0f ;
if (m_position != tmpPos) {
m_position = tmpPos;
m_matrixNeedUpdate = true;
//EWOL_DEBUG("modify m_position=" << m_position << "m m_speed=" << m_speed << "m/s m_gravityForce=" << m_gravityForce << "+" << m_userAcceleration << "m/s2");
}
}

View File

@ -113,17 +113,9 @@ void widget::Scene::GenDraw(ewol::DrawProperty displayProp)
m_size.y);
float ratio = m_size.x / m_size.y;
//EWOL_INFO("ratio : " << ratio);
mat4 tmpProjection;// = etk::matPerspective( M_PI/2.0, ratio, -1, 1);
mat4 tmpProjection = etk::matPerspective( M_PI/2.0, ratio, -1, 1);
if (ratio >= 1.0) {
tmpProjection = etk::matOrtho(-ratio, ratio, -1, 1, -1, 1);
} else {
ratio = 1.0/ratio;
tmpProjection = etk::matOrtho(-1, 1, -ratio, ratio, -1, 1);
}
mat4 tmpScale = etk::matScale(vec3(m_zoom, m_zoom, m_zoom) );
mat4 tmpMat = tmpProjection * tmpScale * m_camera.GetMatrix();
mat4 tmpMat = tmpProjection * m_camera.GetMatrix();
// set internal matrix system :
ewol::openGL::SetMatrix(tmpMat);
@ -175,9 +167,13 @@ bool widget::Scene::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput,
if (type == ewol::keyEvent::typeMouse) {
if (4 == IdInput && ewol::keyEvent::statusUp == statusEvent) {
m_zoom *= 0.91;
vec3 oldPos = m_camera.GetPosition();
oldPos.z -= 0.5;
m_camera.SetPosition(oldPos);
} else if (5 == IdInput && ewol::keyEvent::statusUp == statusEvent) {
m_zoom *= 1.1;
vec3 oldPos = m_camera.GetPosition();
oldPos.z += 0.5;
m_camera.SetPosition(oldPos);
} else if (1 == IdInput) {
if(modeMoving==1 && ewol::keyEvent::statusUp == statusEvent) {
modeMoving = 0;
@ -187,8 +183,8 @@ bool widget::Scene::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput,
} else if (modeMoving==1 && ewol::keyEvent::statusMove == statusEvent) {
vec2 offset = relativePos - oldCursorPos;
vec3 oldPos = m_camera.GetPosition();
oldPos.x += offset.x;
oldPos.y += offset.y;
oldPos.x -= offset.x/50.0;
oldPos.y -= offset.y/50.0;
m_camera.SetPosition(oldPos);
oldCursorPos = relativePos;
}

View File

@ -10,6 +10,7 @@
#include <appl/Debug.h>
#include <appl/TestScene.h>
#include <etk/tool.h>
#include <ewol/widget/Button.h>
#include <ewol/widget/CheckBox.h>
#include <ewol/widget/SizerHori.h>
@ -190,7 +191,9 @@ class stupidCube : public game::Element
virtual bool ArtificialIntelligence(int32_t deltaMicroSecond)
{
if (m_mass == 0.0f) {
Rotate(baseRotationVect, 0.01);
if (baseRotationVect != vec3(0,0,0) ) {
Rotate(baseRotationVect, 0.01);
}
}
return false;
}
@ -214,6 +217,11 @@ void TestScene::OnReceiveMessage(ewol::EObject * CallerObject, const char * even
}
if (eventId == l_eventAddBox) {
stupidCube * tmpp = new stupidCube();
static bool firstTime = true;
if (firstTime==false) {
tmpp->Translate(vec3(etk::tool::frand(-1,1),etk::tool::frand(-1,1),etk::tool::frand(-1,1)));
}
firstTime = false;
m_gameEngine.AddElement(tmpp, true);
} else if (eventId == l_eventAddSphere) {
if (NULL!=m_testWidget) {