vendredi 22 février 2019

désormais avec vos smartphone profiter de la neige virtuelle !


cette fois je vous présente une application que g développé avec processing android pendant mes temps libre au café qui va vous permettre de profiter de la neige virtuelle incorporé dans le plan de la camera et vous pouvez meme prendre des photos, une stimulation 3D virtuelle intégré dans le monde réel sous tt les angles généré en temps réel ... une derniere chose cette application fonctionne correctement que sur des smartphones doté de capteur orientation dans l'espace.

// VR snow and rain

import android.os.Bundle;
import android.view.WindowManager;
import android.view.MotionEvent;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.hardware.SensorEvent;
mport android.hardware.SensorEventListener;
import ketai.camera.*;

Context context;
SensorManager manager;
Sensor sensor;
AccelerometerListener listener;
float ax, ay, az;
float roll,azimuth,pitch;
float psi,theta,phi;
float[] values = new float[4];
float[] m = new float[16];
float xp,yp,zp;
float ux,uy,uz;
float vx,vy,vz;
float px,py,pz;
float ratio;
float k;
float x,y,r;
float tx,ty;
float dr=5;
float aspect=320/240;

KetaiCamera cam;
float time;
int Nmax=300;
float xs[],ys[],zs[];
float L=500;
boolean state= true;

void onCreate(Bundle icicle) {
super.onCreate(icicle);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//requestPermission(this,new String[] {Manifest.permission.CAMERA},PERMISSION_CAMERA);
requestPermission("android.permission.CAMERA");
}

void setup(){
background(0,160,0);
textMode(CENTER);
textSize(50);
stroke(255);
text(" Please Wait...",200,300);
textSize(30);
text("Programmed by Delta Fares",100,100);
text("Mail:deltafares@gmail.com",100,150);
cam = new KetaiCamera(this, 320, 240, 15);
cam.start();
cam.setCameraID((cam.getCameraID() + 0 ) % cam.getNumberOfCameras());
fullScreen(P3D);
orientation(LANDSCAPE);
stroke(0, 255, 0);
strokeWeight(2);
noFill();
rectMode(CENTER);
imageMode(CENTER);

context = getActivity();
manager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
sensor = manager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
listener = new AccelerometerListener();
manager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_GAME);

ratio = width/height;
x=width/2;y=height/2;
xp=0;yp=0;zp=10;
r=0;
vx=vy=0;
k=0.5;
init_snow(L);
}

void draw(){
background(0);
pushMatrix();
ortho(-width/2,width/2,-height/2,height/2,-1000,1000);
translate(width/2.0, height/2.00,-1);
image(cam, 0, 0,width ,height );
if (sensor==null) then text("sparthphone doesn't support Rotation Vector...",10,100);
popMatrix();

lights();
pushMatrix();
monoVR();
if (state) draw_snow(L); else draw_rain(L);
popMatrix();
textSize(40);
stroke(255);
drawUI();
time+=.03;
}

void mousePressed() {
if (mouseX < width/3 && mouseY < 100) state=!state;
if (mouseX>width/2) {xp=xp+dr*px;yp=yp+dr*py;}
if (mouseX<width/2) {xp=xp-dr*px;yp=yp-dr*py;}
if (mouseX>2*width/3 && mouseY<400) {
saveFrame("/sdcard/picture-###.jpg");
textSize(40);
text("saved",100,100);}
}

void onCameraPreviewEvent() {
cam.read();
}

void monoVR() {

// code hidden

}

void init_snow(float l) {
int i;
xs= new float[Nmax];ys= new float[Nmax];zs= new float[Nmax];
for (i=0;i<Nmax;i++) {
xs[i]=random(l)-l/2;ys[i]=random(l)-l/2;zs[i]=random(l)+10;     }
}

void draw_snow(float l) {
int i;
noLights();
stroke(255,255,255);
fill(255,255,255);
strokeWeight(5);
for (i=0;i<Nmax;i++) {
zs[i]-=5;
if (zs[i]<=-100) {
xs[i]=random(l)-l/2;ys[i]=random(l)-l/2;zs[i]=random(l);}
pushMatrix();
rotateX(0.5);
translate(xs[i],ys[i],zs[i]);
// line(xs[i],ys[i],zs[i], xs[i],ys[i],zs[i] );
scale(1.0);
box(1)
popMatrix();
    }
}

void draw_rain(float l) {
int i;
noLights();
stroke(255,255,255,100);
fill(255,255,255,10);
strokeWeight(5);
for (i=0;i<Nmax;i++) {
zs[i]-=20;
if (zs[i]<=-100) {
xs[i]=random(l)-l/2;ys[i]=random(l)-l/2;zs[i]=random(l);}
pushMatrix();
translate(xs[i],ys[i],zs[i]);
scale(0.03,0.03,10.0);
box(1);
popMatrix();
      }
}

void drawUI() {
pushMatrix();
ortho(-width/2,-width/2,-height/2,height/2,-1000,1000);
textAlign(LEFT);
fill(0,0,0,100);
stroke(255,255,255,100);
rect(0, 0, width/3 , 100);
rect(width/3, 0, width/3, 100);
rect((width/3)*2, 0, width/3, 100);
fill(255);
if (state)
text("snow", 0, 10);
else
text("rain", 0, 10);
text("take picture", width/3*2, 10);
popMatrix();
}

class AccelerometerListener implements SensorEventListener {

public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType()==Sensor.TYPE_ROTATION_VECTOR) {
SensorManager.getRotationMatrixFromVector(m,event.values);
SensorManager.getOrientation(m,values);
azimuth = values[0];
pitch= values[1];
roll = values[2]; }
}

public void onAccuracyChanged(Sensor sensor, int accuracy) {
      }
}

dimanche 17 février 2019

NEO MATRIX VERSION AMSTRAD CPC 464 hahaha


10 REM NEO MATRIX VERSION AMSTRAD CPC 464
20 MEMORY &4000-1:MODE 1
30 RESTORE 80:FOR I=0 TO 15:READ A:INK I,A:NEXT I
40 RESTORE 90:FOR I=0 TO 11:READ A:POKE I+MM,A:NEXT I
50 LOAD"NEO.SCR",&4000
60 CALL MM
70 END
80 DATA 0,26,16,3,13,4,25,17,1,12,14,23,22,2,5,6
90 DATA &21,&00,&40,&11,&00,&C0,&01,&00,&40,&ED,&B0,&C9



mardi 12 février 2019

الارض

شكل الارض اقرب الى المسطحة حواسا و ابعد من الكروية عقلا لا يعلم مدى سعتها الا الله , ليس لها حد محدود و لا شكل موجود و لا قطر ممدود من فوقها قبة السماء الدنيا و ما فوق السماوات السبع بخار البحر من العدم ومن تحتها زبد الامواج من العدم, عدم ليس مقرون بالفراغ ولا بالفضاء مطلق غير مقيد بالمكان و الزمان , يعجز خيال العقل وصفه و بيان الكلام نعته و علوم الهندسة حسابه ضعف الطالب و المطلوب سبحان الله الذي لا الاه الا هو محيط بكل شيء علما كائن ازلي الاول و الاخر ليس كمثل شيء

jeudi 29 juin 2017

Soft shading using SSE2 SIMD technology purely in assembly language !!

 note: my 3D rendering software engine  in real time (Fast3D/2D) powered with SSE4



 // function returns the mixing of 2 3d vectors = (1-u)*a+u*b
 // function returns the mixing of 3 3d vector = (1-u-v)*a+u*b+v*c
// this application is useful for the smooth shading of the triangle

inline vec mix(float u,vec a,vec b) {
__asm {
            mov        eax, 03F800000h // 1.0f
            movd      xmm0,eax
            movss     xmm1,u
            subss      xmm0,xmm1 /// 1-u
            shufps     xmm0,xmm0,_MM_SHUFFLE(3, 0, 0, 0) // xmm0 =0,1-u,1-u,1-u
            shufps     xmm1,xmm1,_MM_SHUFFLE(3, 0, 0, 0) // xmm1 =0,u,u,u
            movaps   xmm2,a
            movaps   xmm3,b
            mulps      xmm0,xmm2 /// xmm0 = (1-u)*a
            mulps      xmm1,xmm3 /// xmm1 = u*b
            addps      xmm0,xmm1 // (1-u)*a+u*b
       }
}


// supports only SSE4.2
inline vec mix2(float u,float v,vec a,vec b,vec c)   {
......
}

mercredi 7 juin 2017

filling a triangle with shader color interpolation very useful for Zbuffer algorithm

Type pixel
x as integer
y as integer
r as integer
g as integer
b as integer
end type

ScreenRes 640, 480, 16,2,0
'screenset 1,0
FUNCTION max(x as integer,y as integer) as integer
 if (x>y) then return x else return y
end function    

FUNCTION min(x as integer,y as integer) as integer
 if (x>y) then return y else return x
end function    

sub triangle(a as pixel, b as pixel, c as pixel)
 dim as single xmin,ymin,xmax,ymax,x,y
 dim as single u,v,det
 dim as pixel am,ab,ac,m
 dim as integer red,green,blue

 xmin = min(a.x,min(b.x,c.x)):xmax = max(a.x,max(b.x,c.x))
 ymin = min(a.y,min(b.y,c.y)):ymax = max(a.y,max(b.y,c.y))

  ab.x = b.x-a.x: ab.y = b.y-a.y
  ac.x = c.x-a.x: ac.y = c.y-a.y
  
 for y = ymin to ymax
     for x = xmin to xmax
         m.x = x:m.y= y 
         am.x = x-a.x: am.y = y-a.y
         det  = ab.x*ac.y-ac.x*ab.y
         u  = (am.x*ac.y-ac.x*am.y)/det: v  = -(am.x*ab.y-ab.x*am.y)/det
         
         red  = u*b.r+v*c.r+(1-u-v)*a.r:
         green  = u*b.g+v*c.g+(1-u-v)*a.g
         blue  = u*b.b+v*c.b+(1-u-v)*a.b
         
         if ( (u>=0) and ( v>=0) and ( u+v<=1))  then pset (x,y),RGB(red,green,blue) 
           
       next x
   next y

end sub

dim as single i
dim as pixel a,b,c


for i = 0 to  2000 
a.x = 640*rnd: a.y = 480*rnd
b.x = 640*rnd:b.y = 480*rnd
c.x = 640*rnd:c.y = 480*rnd

 a.r = 255*rnd: a.g = 255*rnd: a.b = 255*rnd
 b.r = 255*rnd: b.g = 255*rnd: b.b = 255*rnd
 c.r = 255*rnd: c.g = 255*rnd: c.b = 255*rnd
triangle(a,b,c)

next i



sleep

vendredi 19 mai 2017

FastMath 3D Geometry in pure inline assembly language supports SIMD SSE 4.1

//  3D geometry   support SIMD SSE4.1
//  programmed by delta fares

#include <emmintrin.h>
#include <stdio.h>

typedef __m128 vec;
typedef struct {
__m128 x;
__m128 y;
__m128 z;}  matrix;

// 3D  Math 

vec vec4(float x,float y, float z,float w);
vec vec3(float x,float y, float z);
vec vec2(float x,float y);
inline vec operator +(vec a,vec b);
inline vec operator -(vec a,vec b);
inline vec operator *(float k,vec v);
inline vec operator *(vec v,float k);
inline vec operator /(vec v,float k);
inline vec cross(vec a, vec b);
inline float norm(vec v);
inline float norm2(vec v);  // SSE4.1
inline float dot(vec a,vec b);
inline float dot2(vec a,vec b); //SSE4.1
inline float  dist2(vec a,vec b); //SSE41
inline void normalize(vec& v);
inline void normalize2(vec& v);  //SSE4.1
inline vec reflect(vec v,vec n);  //SSE4.1

matrix mat3(float a11,float a21,float a31,
                   float a12,float a22,float a32,
                   float a13,float a23,float a33);

matrix mat4(float a11,float a21,float a31,float a41,
                   float a12,float a22,float a32,float a42,
                   float a13,float a23,float a33,float a43);


inline vec  operator *(matrix& mat,vec v);
.
.
// body program

vec vec3(float x,float y, float z) {
return _mm_set_ps(0,z,y,x);}
.
.
inline vec operator +(vec a,vec b) {
__asm {
             movaps xmm0,a
             movaps xmm1,b
             addps xmm0,xmm1
      }
};

inline vec operator -(vec a,vec b) {
__asm {
             movaps xmm0,a
             movaps xmm1,b
             subps xmm0,xmm1
      }
};

.
.
inline vec operator *(vec v,float k) {
_asm {
            movss xmm0,k
            shufps xmm0,xmm0,00h
            movaps xmm1,v
            mulps xmm0,xmm1
     }
};
.
.
inline void normalize(vec& v) {
  _asm {
              mov    eax,v
              movaps xmm1,[eax]
              movaps xmm0,xmm1   //  xmm0 = v
              mulps  xmm1,xmm1  //  x² y² z²
              movaps xmm2,xmm1
              movaps xmm3,xmm1
              shufps xmm1,xmm1,_MM_SHUFFLE(0, 0, 0, 0)   //  xmm1 = x²
              shufps xmm2,xmm2,_MM_SHUFFLE(1, 1, 1, 1)   //  xmm2 = y²
              shufps xmm3,xmm3,_MM_SHUFFLE(2, 2, 2, 2)   //  xmm3 = z²
              addps  xmm1,xmm2            
              addps  xmm1,xmm3            // xmm1 = x²+y²+z²
              sqrtps xmm1,xmm1             // xmm1= sqrt(v*v)
              divps  xmm0,xmm1              // xmm0 = v/sqrt(v*v)
              movaps [eax],xmm0
       }

}
.
.
.
inline vec reflect(vec v,vec n) {

    return 2*dot2(v,n)*n-v;
}

inline vec  operator *(matrix& mat,vec v) {
    vec res;
    res.m128_f32[0] = dot2(mat.x,v);
    res.m128_f32[1] = dot2(mat.y,v);
    res.m128_f32[2] = dot2(mat.z,v);
    res.m128_f32[3] = 0;
    return res;
}


int main(int argc, char* argv[])  {

matrix mat = mat3(1 , 8,3,
                             3,-1,1,
                             4, 2,1);

vec a,b,c,V;

a = vec3(51,13,10);
b = vec3(1,1,0);

c =dot(a,b)*cross(a,b)+3*b+a;
show(c);
normalize2(c);
show(c);

vec r = reflect(b,a);
show(r);

printf("%f %f %f\n", dot(a,b),dot2(a,b));   //  compare SSE2 with SSE4.1

V = mat*a;
show(V);
return 0;
}