Permalink
Browse files

added python aop sample

  • Loading branch information...
1 parent f5759c4 commit de713e410d470eb8d3b8c1c4fa111ee629059bf8 @stanfeldman committed May 17, 2012
@@ -1,118 +1,11 @@
package mygame;
-import com.jme3.app.SimpleApplication;
-import com.jme3.input.KeyInput;
-import com.jme3.input.controls.ActionListener;
-import com.jme3.input.controls.AnalogListener;
-import com.jme3.input.controls.KeyTrigger;
-import com.jme3.light.DirectionalLight;
-import com.jme3.material.Material;
-import com.jme3.math.ColorRGBA;
-import com.jme3.math.Vector3f;
-import com.jme3.renderer.RenderManager;
-import com.jme3.scene.Geometry;
-import com.jme3.scene.Node;
-import com.jme3.scene.Spatial;
-import com.jme3.scene.shape.Box;
-
-public class Main extends SimpleApplication
+public class Main
{
public static void main(String[] args)
{
- Main app = new Main();
+ Shooter app = new Shooter();
app.setShowSettings(false);
app.start();
}
-
- @Override
- public void simpleInitApp()
- {
- int n = 10000;
- for(int i = 0; i < n; ++i)
- {
- Box box1 = new Box(new Vector3f(n/2+i,1,1), 1,1,1);
- Geometry geom1 = new Geometry("Box", box1);
- Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
- mat1.setColor("Color", ColorRGBA.White);
- //mat1.setTexture("ColorMap", assetManager.loadTexture("textures/monkey.jpg"));
- geom1.setMaterial(mat1);
- geom1.setLocalScale(0.05f);
- rootNode.attachChild(geom1);
- }
- /*Box box2 = new Box(new Vector3f(1,3,1), 1,1,1);
- Geometry geom2 = new Geometry("Box", box2);
- Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
- //mat2.setColor("Color", ColorRGBA.Red);
- geom2.setMaterial(mat2);
- Node pivot = new Node("pivot");
- rootNode.attachChild(pivot);
- pivot.attachChild(geom1);
- pivot.attachChild(geom2);
- pivot.rotate(.4f,.4f,.0f);*/
- /*teapot = assetManager.loadModel("models/teapot.obj");
- //teapot.move(1, 1, 1);
- Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
- teapot.setMaterial(mat3);
- rootNode.attachChild(teapot);
- Spatial wall = new Geometry("Box", new Box(Vector3f.ZERO, 2.5f, 2.5f, 1.0f));
- Material wall_material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
- wall_material.setTexture("ColorMap", assetManager.loadTexture("textures/brickwall.jpg"));
- wall.setMaterial(wall_material);
- wall.setLocalTranslation(2.0f,-2.5f,0.0f);
- rootNode.attachChild(wall);
- viewPort.setBackgroundColor(ColorRGBA.LightGray);
- initKeys();*/
- }
-
- @Override
- public void simpleUpdate(float tpf)
- {
- //teapot.rotate(0, 2*tpf, 0);
- }
-
- @Override
- public void simpleRender(RenderManager rm) {
- //TODO: add render code
- }
-
- private void initKeys()
- {
- inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P));
- inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_L));
- inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_R));
- inputManager.addListener(actionListener, new String[]{"Pause"});
- inputManager.addListener(analogListener, new String[]{"Left","Right"});
- }
-
- private ActionListener actionListener = new ActionListener()
- {
- public void onAction(String name, boolean isPressed, float tpf)
- {
- if(name.equals("Pause") && !isPressed)
- isRunning = !isRunning;
- }
- };
-
- private AnalogListener analogListener = new AnalogListener()
- {
- public void onAnalog(String name, float value, float tpf)
- {
- if(isRunning)
- {
- if(name.equals("Left"))
- {
- Vector3f v = teapot.getLocalTranslation();
- teapot.setLocalTranslation(v.x - value*speed, v.y, v.z);
- }
- else if(name.equals("Right"))
- {
- Vector3f v = teapot.getLocalTranslation();
- teapot.setLocalTranslation(v.x + value*speed, v.y, v.z);
- }
- }
- }
- };
-
- protected Spatial teapot;
- protected boolean isRunning = true;
}
@@ -10,6 +10,8 @@
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.material.Material;
+import com.jme3.math.FastMath;
+import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
@@ -74,8 +76,11 @@ private void initPhysics()
private void initCamera()
{
- cam.setLocation(new Vector3f(0, 4f, 6f));
- cam.lookAt(new Vector3f(2,2,0), Vector3f.UNIT_Y);
+ cam.setLocation(new Vector3f(0, 1f, 6f));
+ //cam.lookAt(new Vector3f(0,0,0), new Vector3f(0,0,0));
+ Quaternion rotator = new Quaternion();
+ rotator.fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_Y);
+ //cam.setRotation(rotator);
}
private void initCrossHairs()
@@ -111,21 +116,35 @@ private void initWall()
for(int j = 0; j < 5; ++j)
{
Vector3f loc = new Vector3f(j, i*2*brickHeight, 0);
- createBrick(loc, brickLength, brickWidth, brickHeight);
+ createBrick(loc, brickLength, brickWidth, brickHeight, 2);
}
+
+ Vector3f loc2 = new Vector3f(0, 1, 2);
+ Box brickBox = new Box(Vector3f.ZERO, brickLength, brickWidth, brickHeight);
+ brickBox.scaleTextureCoordinates(new Vector2f(1f, .5f));
+ Geometry brickGeo = new Geometry("brick", brickBox);
+ brickGeo.setMaterial((Material)resources.get("materials.brick"));
+ brickGeo.setLocalTranslation(loc2);
+ rootNode.attachChild(brickGeo);
+ Quaternion quat1 = new Quaternion();
+ quat1.fromAngleAxis(-FastMath.QUARTER_PI, Vector3f.UNIT_Z);
+ Quaternion quat2 = new Quaternion();
+ quat2.fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_Y);
+ brickGeo.rotate(quat1.mult(quat2));
}
- private void createBrick(Vector3f loc, float length, float width, float height)
+ private Geometry createBrick(Vector3f loc, float length, float width, float height, float mass)
{
Box brickBox = new Box(Vector3f.ZERO, length, height, width);
brickBox.scaleTextureCoordinates(new Vector2f(1f, .5f));
Geometry brickGeo = new Geometry("brick", brickBox);
brickGeo.setMaterial((Material)resources.get("materials.brick"));
brickGeo.setLocalTranslation(loc);
rootNode.attachChild(brickGeo);
- RigidBodyControl brickPhysics = new RigidBodyControl(2f);
+ RigidBodyControl brickPhysics = new RigidBodyControl(mass);
brickGeo.addControl(brickPhysics);
bulletAppState.getPhysicsSpace().add(brickPhysics);
+ return brickGeo;
}
private void initKeys()
@@ -0,0 +1,111 @@
+package mygame;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.input.KeyInput;
+import com.jme3.input.controls.ActionListener;
+import com.jme3.input.controls.AnalogListener;
+import com.jme3.input.controls.KeyTrigger;
+import com.jme3.light.DirectionalLight;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.Vector3f;
+import com.jme3.renderer.RenderManager;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.Node;
+import com.jme3.scene.Spatial;
+import com.jme3.scene.shape.Box;
+
+public class Simple extends SimpleApplication
+{
+ @Override
+ public void simpleInitApp()
+ {
+ int n = 10000;
+ for(int i = 0; i < n; ++i)
+ {
+ Box box1 = new Box(new Vector3f(n/2+i,1,1), 1,1,1);
+ Geometry geom1 = new Geometry("Box", box1);
+ Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ mat1.setColor("Color", ColorRGBA.White);
+ //mat1.setTexture("ColorMap", assetManager.loadTexture("textures/monkey.jpg"));
+ geom1.setMaterial(mat1);
+ geom1.setLocalScale(0.05f);
+ rootNode.attachChild(geom1);
+ }
+ /*Box box2 = new Box(new Vector3f(1,3,1), 1,1,1);
+ Geometry geom2 = new Geometry("Box", box2);
+ Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
+ //mat2.setColor("Color", ColorRGBA.Red);
+ geom2.setMaterial(mat2);
+ Node pivot = new Node("pivot");
+ rootNode.attachChild(pivot);
+ pivot.attachChild(geom1);
+ pivot.attachChild(geom2);
+ pivot.rotate(.4f,.4f,.0f);*/
+ /*teapot = assetManager.loadModel("models/teapot.obj");
+ //teapot.move(1, 1, 1);
+ Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
+ teapot.setMaterial(mat3);
+ rootNode.attachChild(teapot);
+ Spatial wall = new Geometry("Box", new Box(Vector3f.ZERO, 2.5f, 2.5f, 1.0f));
+ Material wall_material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+ wall_material.setTexture("ColorMap", assetManager.loadTexture("textures/brickwall.jpg"));
+ wall.setMaterial(wall_material);
+ wall.setLocalTranslation(2.0f,-2.5f,0.0f);
+ rootNode.attachChild(wall);
+ viewPort.setBackgroundColor(ColorRGBA.LightGray);
+ initKeys();*/
+ }
+
+ @Override
+ public void simpleUpdate(float tpf)
+ {
+ //teapot.rotate(0, 2*tpf, 0);
+ }
+
+ @Override
+ public void simpleRender(RenderManager rm) {
+ //TODO: add render code
+ }
+
+ private void initKeys()
+ {
+ inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P));
+ inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_L));
+ inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_R));
+ inputManager.addListener(actionListener, new String[]{"Pause"});
+ inputManager.addListener(analogListener, new String[]{"Left","Right"});
+ }
+
+ private ActionListener actionListener = new ActionListener()
+ {
+ public void onAction(String name, boolean isPressed, float tpf)
+ {
+ if(name.equals("Pause") && !isPressed)
+ isRunning = !isRunning;
+ }
+ };
+
+ private AnalogListener analogListener = new AnalogListener()
+ {
+ public void onAnalog(String name, float value, float tpf)
+ {
+ if(isRunning)
+ {
+ if(name.equals("Left"))
+ {
+ Vector3f v = teapot.getLocalTranslation();
+ teapot.setLocalTranslation(v.x - value*speed, v.y, v.z);
+ }
+ else if(name.equals("Right"))
+ {
+ Vector3f v = teapot.getLocalTranslation();
+ teapot.setLocalTranslation(v.x + value*speed, v.y, v.z);
+ }
+ }
+ }
+ };
+
+ protected Spatial teapot;
+ protected boolean isRunning = true;
+}
View
@@ -0,0 +1,38 @@
+from sys import path
+path.append("/home/stanislavfeldman/projects/python/putils/")
+from putils.aop import Aspect
+
+
+class MyAspect(Aspect):
+ def on_enter(self, call):
+ print "on enter: ", call.args
+
+ def on_success(self, call):
+ print "on success: ", call.result
+
+ def on_fail(self, call):
+ print "on fail: ", call.exception
+
+
+@MyAspect()
+class MyClass(object):
+ def __init__(self):
+ self.var = 5
+ def m1(self, n):
+ n+1
+ def m2(self, n):
+ return n+1
+ def m3(self, n):
+ raise ValueError("error!")
+
+
+@MyAspect()
+def func(x):
+ return x+1
+
+
+mc = MyClass()
+mc.m1(5)
+mc.m2(6)
+mc.m3(7)
+func(555)
View
@@ -1,10 +1,23 @@
from Crypto.Cipher import AES
-
key = "my super secret!"
plaintext = "hi vasya z osaji"
encoder = AES.new(key, AES.MODE_ECB)
ciphertext = encoder.encrypt(plaintext)
-print ciphertext.encode("hex")
decoder = AES.new(key, AES.MODE_ECB)
plaintext2 = decoder.decrypt(ciphertext)
-print plaintext == plaintext2
+print "symmetric crypto: ", plaintext == plaintext2
+
+from Crypto.Hash import SHA256
+hash_function = SHA256.new()
+hash_function.update(plaintext)
+h1 = hash_function.hexdigest()
+hash_function = SHA256.new()
+hash_function.update("hi vasya z osaji")
+h2 = hash_function.hexdigest()
+print "hash: ", h1 == h2
+
+from Crypto.PublicKey import RSA
+private_key = RSA.generate(1024)
+public_key = private_key.publickey()
+ciphertext = public_key.encrypt(plaintext, "random str")
+print "assymetric crypto: ", plaintext == private_key.decrypt(ciphertext)

0 comments on commit de713e4

Please sign in to comment.