Skip to content

Instantly share code, notes, and snippets.

@hiroakioishi
hiroakioishi / ChangeMouseSpeed
Created April 4, 2015 09:01
[Unity:C#] マウスの移動速度を変える
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System;
public class ChangeMouseSpeed : MonoBehaviour {
public const uint SPI_SETMOUSESPEED = 0x0071;
public const uint SPI_GETMOUSESPEED = 0x0070;
@hiroakioishi
hiroakioishi / delete_all
Last active August 29, 2015 14:20
[Blender:Python] すべてのオブジェクトを削除する
for item in bpy.context.scene.objects:
bpy.context.scene.objects.unlink(item)
for item in bpy.data.objects:
bpy.data.objects.remove(item)
for item in bpy.data.meshes:
bpy.data.meshes.remove(item)
for item in bpy.data.materials:
@hiroakioishi
hiroakioishi / offset_vertices_of_mesh_objects
Created April 30, 2015 16:41
[Blender:Python] シーン中に存在するタイプがMESHのオブジェクトの頂点を任意の範囲のランダム値でずらす
import bpy
import random
def offset_vertices_of_mesh_objects (vertOffsetRnd_):
for obj in bpy.context.scene.objects:
#print(obj.type)
if obj.type == 'MESH':
print(obj.name)
for vert in obj.data.vertices:
@hiroakioishi
hiroakioishi / get_keyframes
Last active August 29, 2015 14:22
[Blender:Python] 指定した名前のアクションのキーフレームの配列を返す
def get_keyframes(action_name):
keyframes = []
action = bpy.data.actions[action_name]
if action is not None and action is not None:
for fcu in action.fcurves:
for keyframe in fcu.keyframe_points:
x, y = keyframe.co
if x not in keyframes:
keyframes.append((math.ceil(x)))
return keyframes
@hiroakioishi
hiroakioishi / GetRandomEnum
Created September 1, 2015 18:14
enum ランダムで返す
static T GetRandomEnum<T>()
{
System.Array A = System.Enum.GetValues(typeof(T));
T V = (T)A.GetValue(UnityEngine.Random.Range(0,A.Length));
return V;
}
state = GetRandomEnum<State>();
@hiroakioishi
hiroakioishi / calcDistancePointAndPlane.cs
Last active December 5, 2015 14:12
ある点から平面までの距離
float calcDistancePointAndPlane (Vector3 p, Vector3 v0, Vector3 v1, Vector3 v2) {
Vector3 n = Vector3.Normalize (Vector3.Cross (v1 - v0, v2 - v1));
Vector3 g = (v0 + v1 + v2) / 3.0f;
return Mathf.Abs (Vector3.Dot (n, p - g));
}
@hiroakioishi
hiroakioishi / calcIntersectionLineSegmentAndPlane.cs
Last active December 5, 2015 14:30
3次元座標上の線分と平面の交点座標を求める
Vector3 calcIntersectionLineSegmentAndPlane (Vector3 a, Vector3 b, Vector3 v0, Vector3 v1, Vector3 v2) {
float distAP = calcDistancePointAndPlane (a, v0, v1, v2);
float distBP = calcDistancePointAndPlane (b, v0, v1, v2);
float t = distAP / (distAP + distBP);
return (b - a) * t + a;
}
@hiroakioishi
hiroakioishi / detectPointIsEnclosedByPolygon.cs
Last active December 6, 2015 03:19
ポリゴン上に点が含まれるかを判定
/// <summary>
/// ポリゴン上に点が含まれるかを判定
/// </summary>
bool detectPointIsEnclosedByPolygon (Vector3 p, Vector3 v0, Vector3 v1, Vector3 v2) {
Vector3 n = Vector3.Normalize (Vector3.Cross (v1 - v0, v2 - v1));
Vector3 n0 = Vector3.Normalize (Vector3.Cross (v1 - v0, p - v1));
Vector3 n1 = Vector3.Normalize (Vector3.Cross (v2 - v1, p - v2));
Vector3 n2 = Vector3.Normalize (Vector3.Cross (v0 - v2, p - v0));
@hiroakioishi
hiroakioishi / detectIsIntersectedLineSegmentAndPolygon.cs
Last active December 6, 2015 03:19
3次元座標上の線分と3角ポリゴンが交差してるかを判定
// -------------------------------------------------------------
/// <summary>
/// 3次元座標上の線分と3角ポリゴンが交差してるかを判定
/// </summary>
bool detectIsIntersectedLineSegmentAndPolygon (Vector3 a, Vector3 b, Vector3 v0, Vector3 v1, Vector3 v2) {
bool bCollision = detectCollisionLineSegmentAndPlane (a, b, v0, v1, v2);
if (bCollision) {
Vector3 p = calcIntersectionLineSegmentAndPlane (a, b, v0, v1, v2);
@hiroakioishi
hiroakioishi / DepthMapGenerator.cs
Last active December 6, 2015 14:28
Unity: Kinect v2 で GetDepthMap () で取得可能なデプスマップを生成する
using UnityEngine;
using System.Collections;
using Windows.Kinect;
public class DepthMapGenerator : MonoBehaviour {
public GameObject depthSourceManager;
private DepthSourceManager depthSourceManagerScript;
[Range (1, 8000)]