summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-01-03 11:06:53 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-01-03 11:06:53 -0300
commitcef3bd026fa6a6c1b2e19693b111210b3ce876ac (patch)
treebeea572b5c526fe8ba72669bb1110b08be07a714
parent60afd79a6e2354e0254c280d826bc6f12f68ffa1 (diff)
-fixed issue with denormals in half precission, closes #1073
-added h_offset and v_offset to 3D Camera, should allow to do the same as in #1102
-rw-r--r--bin/tests/test_math.cpp1
-rw-r--r--core/io/json.cpp2
-rw-r--r--core/ustring.cpp16
-rw-r--r--core/ustring.h2
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp4
-rw-r--r--scene/3d/camera.cpp35
-rw-r--r--scene/3d/camera.h8
7 files changed, 60 insertions, 8 deletions
diff --git a/bin/tests/test_math.cpp b/bin/tests/test_math.cpp
index 2db945d5fd..ea324a7381 100644
--- a/bin/tests/test_math.cpp
+++ b/bin/tests/test_math.cpp
@@ -80,6 +80,7 @@ MainLoop* test() {
{
+
// print_line("NUM: "+itos(237641278346127));
print_line("NUM: "+itos(-128));
return NULL;
diff --git a/core/io/json.cpp b/core/io/json.cpp
index a83d7e4d6e..88a23eb4cd 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -250,7 +250,7 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token& r_toke
if (p_str[idx]=='-' || (p_str[idx]>='0' && p_str[idx]<='9')) {
//a number
const CharType *rptr;
- double number = String::to_double(&p_str[idx],-1,&rptr);
+ double number = String::to_double(&p_str[idx],&rptr);
idx+=(rptr - &p_str[idx]);
r_token.type=TK_NUMBER;
r_token.value=number;
diff --git a/core/ustring.cpp b/core/ustring.cpp
index d75c21d16e..50e5dc95c7 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -626,7 +626,7 @@ Vector<float> String::split_floats(const String &p_splitter,bool p_allow_empty)
if (end<0)
end=len;
if (p_allow_empty || (end>from))
- ret.push_back(String::to_double(&c_str()[from],end-from));
+ ret.push_back(String::to_double(&c_str()[from]));
if (end==len)
break;
@@ -654,8 +654,11 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters,bool p_a
spl_len=p_splitters[idx].length();
}
- if (p_allow_empty || (end>from))
- ret.push_back(String::to_double(&c_str()[from],end-from));
+ if (p_allow_empty || (end>from)) {
+ double d = String::to_double(&c_str()[from]);
+ print_line("get db: "+rtos(d));
+ ret.push_back(String::to_double(&c_str()[from]));
+ }
if (end==len)
break;
@@ -1959,8 +1962,10 @@ float String::to_float() const {
return to_double();
}
-double String::to_double(const CharType* p_str, int p_len, const CharType **r_end) {
+double String::to_double(const CharType* p_str, const CharType **r_end) {
+ return built_in_strtod<CharType>(p_str,(CharType**)r_end);
+#if 0
#if 0
//ndef NO_USE_STDLIB
return wcstod(p_str,p_len<0?NULL:p_str+p_len);
@@ -2053,6 +2058,7 @@ double String::to_double(const CharType* p_str, int p_len, const CharType **r_en
return sign*(integer+decimal)*Math::pow(10,exp_sign*exp);
#endif
+#endif
}
int64_t String::to_int(const CharType* p_str,int p_len) {
@@ -3437,7 +3443,7 @@ String String::percent_encode() const {
uint8_t c = cs[i];
if ( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || c=='-' || c=='_' || c=='~' || c=='.') {
- char p[2]={c,0};
+ char p[2]={(char)c,0};
encoded+=p;
} else {
char p[4]={'%',0,0,0};
diff --git a/core/ustring.h b/core/ustring.h
index 8fe3a95463..e1d6761742 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -142,7 +142,7 @@ public:
int64_t to_int64() const;
static int to_int(const char* p_str);
static double to_double(const char* p_str);
- static double to_double(const CharType* p_str, int p_len=-1, const CharType **r_end=NULL);
+ static double to_double(const CharType* p_str, const CharType **r_end=NULL);
static int64_t to_int(const CharType* p_str,int p_len=-1);
String capitalize() const;
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index ccbba2f51c..b4791fc6d8 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -139,11 +139,13 @@ static _FORCE_INLINE_ uint16_t make_half_float(float f) {
else if (exp <= 0x38000000)
{
- // store a denorm half-float value or zero
+ /*// store a denorm half-float value or zero
exp = (0x38000000 - exp) >> 23;
mantissa >>= (14 + exp);
hf = (((uint16_t)sign) << 15) | (uint16_t)(mantissa);
+ */
+ hf=0; //denormals do not work for 3D
}
else
{
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp
index 1db9886261..27420f8002 100644
--- a/scene/3d/camera.cpp
+++ b/scene/3d/camera.cpp
@@ -86,6 +86,10 @@ bool Camera::_set(const StringName& p_name, const Variant& p_value) {
set_keep_aspect_mode(KeepAspect(int(p_value)));
else if (p_name=="vaspect")
set_keep_aspect_mode(p_value?KEEP_WIDTH:KEEP_HEIGHT);
+ else if (p_name=="h_offset")
+ h_offset=p_value;
+ else if (p_name=="v_offset")
+ v_offset=p_value;
else if (p_name=="current") {
if (p_value.operator bool()) {
make_current();
@@ -128,6 +132,10 @@ bool Camera::_get(const StringName& p_name,Variant &r_ret) const {
}
} else if (p_name=="visible_layers") {
r_ret=get_visible_layers();
+ } else if (p_name=="h_offset") {
+ r_ret=get_h_offset();
+ } else if (p_name=="v_offset") {
+ r_ret=get_v_offset();
} else if (p_name=="environment") {
r_ret=get_environment();
} else
@@ -170,12 +178,16 @@ void Camera::_get_property_list( List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo( Variant::BOOL, "current" ) );
p_list->push_back( PropertyInfo( Variant::INT, "visible_layers",PROPERTY_HINT_ALL_FLAGS ) );
p_list->push_back( PropertyInfo( Variant::OBJECT, "environment",PROPERTY_HINT_RESOURCE_TYPE,"Environment" ) );
+ p_list->push_back( PropertyInfo( Variant::REAL, "h_offset" ) );
+ p_list->push_back( PropertyInfo( Variant::REAL, "v_offset" ) );
}
void Camera::_update_camera() {
Transform tr = get_camera_transform();
+ tr.origin+=tr.basis.get_axis(1)*v_offset;
+ tr.origin+=tr.basis.get_axis(0)*h_offset;
VisualServer::get_singleton()->camera_set_transform( camera, tr );
// here goes listener stuff
@@ -757,6 +769,27 @@ void Camera::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, cons
}
+void Camera::set_v_offset(float p_offset) {
+
+ v_offset=p_offset;
+ _update_camera();;
+}
+
+float Camera::get_v_offset() const {
+
+ return v_offset;
+}
+
+void Camera::set_h_offset(float p_offset) {
+ h_offset=p_offset;
+ _update_camera();
+}
+
+float Camera::get_h_offset() const {
+
+ return h_offset;
+}
+
Camera::Camera() {
@@ -772,6 +805,8 @@ Camera::Camera() {
set_perspective(60.0,0.1,100.0);
keep_aspect=KEEP_HEIGHT;
layers=0xfffff;
+ v_offset=0;
+ h_offset=0;
VisualServer::get_singleton()->camera_set_visible_layers(camera,layers);
//active=false;
}
diff --git a/scene/3d/camera.h b/scene/3d/camera.h
index bac8173bb7..950688dfda 100644
--- a/scene/3d/camera.h
+++ b/scene/3d/camera.h
@@ -61,6 +61,8 @@ private:
float fov;
float size;
float near,far;
+ float v_offset;
+ float h_offset;
KeepAspect keep_aspect;
RID camera;
@@ -140,6 +142,12 @@ public:
void look_at(const Vector3& p_target, const Vector3& p_up_normal);
void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal);
+ void set_v_offset(float p_offset);
+ float get_v_offset() const;
+
+ void set_h_offset(float p_offset);
+ float get_h_offset() const;
+
Camera();
~Camera();