Commits

Anonymous committed 8bf20fa

isometric projection works

Comments (0)

Files changed (1)

 import os
 import collections
 import ctypes
+from math import *
+from pprint import pprint, pformat
 
-def axonometric_texture(img, drawable, theta, phi) :
+def axonometric_texture(img, drawable, theta, phi, alpha) :
 
         MessageBox = ctypes.windll.user32.MessageBoxA
 
-        theta = math.radians(theta)
-        phi = math.radians(phi)
+        theta = radians(theta)
+        phi = radians(phi)
+        alpha = radians(alpha)
+
+        U = [0,1,0]
+        R = [
+                [
+                    cos(theta) + U[0]**2 *(1-cos(theta)),
+                    U[0]*U[1]*(1 - cos(theta)) - U[2] * sin(theta),
+                    U[0] * U[2] * (1-cos(theta)) + U[1] * sin(theta)
+                ],
+                [
+                    U[1] * U[0] * (1 - cos(theta)) + U[2] * sin(theta),
+                    cos(theta) + U[1] * U[1] * (1 - cos(theta)),
+                    U[1] * U[2] * (1 - cos(theta)) - U[0] * sin(theta)
+                ],
+                [
+                    U[2] * U[0] * (1 - cos(theta)) - U[1] * sin(theta),
+                    U[2] * U[1] * (1-cos(theta)) + U[0] * sin(theta),
+                    cos(theta) + U[2] * U[2] * (1 - cos(theta))
+                ]
+            ]
+
+        Rx = [
+                [1,0,0],
+                [0,cos(theta),1 * sin(theta)],
+                [0,-1 * sin(theta),cos(theta)]
+            ]
+
+        Ry = [
+            [cos(phi),0,sin(phi)],
+            [0,1,0],
+            [-1*sin(phi),0,cos(theta)]
+            ]
+        Rz = [[cos(alpha),-1 * sin(alpha),0],[sin(alpha),cos(alpha),0],[0,0,1]]
 
         layer = img.active_layer
 
-        hp = layer.height / math.tan(theta)
-        dx = math.cos(phi) * hp
+        pdb.gimp_message("original\nwidth:%s\nheight:%s\n"%(layer.width, layer.height))
 
-        transform = pdb.gimp_item_transform_shear(
-                img.active_layer,
-                0,
-                -dx
-        )
+        pdb.gimp_item_transform_rotate(layer, alpha, False, layer.width/2, layer.height/2)
+        pdb.gimp_message("rotated\nwidth:%s\nheight:%s\n"%(layer.width, layer.height))
 
-        img.active_layer = transform
-
-        transform.scale(
-                transform.width,
-                hp
-        )
-
+        pdb.gimp_item_transform_scale(layer, 0,0,cos(phi) * layer.width, cos(theta) * layer.height)
+        pdb.gimp_message("scaled\nwidth:%s\nheight:%s\n"%(layer.width, layer.height))
 
         return None
 
 def dimetric_2to1_texture(img, drawable) :
 
-        axonometric_texture(img, drawable, 24, 78)
+        axonometric_texture(img, drawable, 24, 78, 0)
 
         return None
 
         [
             (PF_FLOAT, "theta", "theta:", None),
             (PF_FLOAT, "phi", "phi:", None),
+            (PF_FLOAT, "alpha", "alpha:", None),
         ],
         #results
         [],