[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(1,0,0), m_angles.x );
m_matrix.Rotate(vec3(0,1,0), m_angles.y ); m_matrix.Rotate(vec3(0,1,0), m_angles.y );
m_matrix.Rotate(vec3(0,0,1), m_angles.z ); 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); 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] pos Position of the camera.
* @param[in] angles Rotations angles 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. * @brief Set the position of the camera.
* @param[in] pos Position of the camera. * @param[in] pos Position of the camera.
*/ */

View File

@ -30,9 +30,8 @@ game::Element::Element(etk::UString meshResource) :
} }
uniqueId++; uniqueId++;
Scale(vec3(100,100,100) ); //Scale(vec3(100,100,100) );
//m_property.Rotate(m_property.m_angle, rotx); //Translate(vec3(0.0,0.0,-10.0));
//Translate(vec3(0.01,0.0,0.0));
} }
game::Element::~Element(void) game::Element::~Element(void)
@ -89,8 +88,11 @@ void game::Element::ProcessPosition(float delta)
vec3 m_speed0(m_speed); vec3 m_speed0(m_speed);
vec3 curentAcceleration(m_gravityForce + m_userAcceleration); vec3 curentAcceleration(m_gravityForce + m_userAcceleration);
m_speed += curentAcceleration*delta; m_speed += curentAcceleration*delta;
m_position += m_speed0*delta + curentAcceleration*delta*delta/2.0f ; vec3 tmpPos = m_position +m_speed0*delta + curentAcceleration*delta*delta/2.0f ;
if (m_position != tmpPos) {
m_position = tmpPos;
m_matrixNeedUpdate = true; 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"); //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); m_size.y);
float ratio = m_size.x / m_size.y; float ratio = m_size.x / m_size.y;
//EWOL_INFO("ratio : " << ratio); //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) { mat4 tmpMat = tmpProjection * m_camera.GetMatrix();
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();
// set internal matrix system : // set internal matrix system :
ewol::openGL::SetMatrix(tmpMat); 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 (type == ewol::keyEvent::typeMouse) {
if (4 == IdInput && ewol::keyEvent::statusUp == statusEvent) { 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) { } 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) { } else if (1 == IdInput) {
if(modeMoving==1 && ewol::keyEvent::statusUp == statusEvent) { if(modeMoving==1 && ewol::keyEvent::statusUp == statusEvent) {
modeMoving = 0; 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) { } else if (modeMoving==1 && ewol::keyEvent::statusMove == statusEvent) {
vec2 offset = relativePos - oldCursorPos; vec2 offset = relativePos - oldCursorPos;
vec3 oldPos = m_camera.GetPosition(); vec3 oldPos = m_camera.GetPosition();
oldPos.x += offset.x; oldPos.x -= offset.x/50.0;
oldPos.y += offset.y; oldPos.y -= offset.y/50.0;
m_camera.SetPosition(oldPos); m_camera.SetPosition(oldPos);
oldCursorPos = relativePos; oldCursorPos = relativePos;
} }

View File

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