psaudo
it = list1.begin();
while( it != list1.end() )
{
if( *it == (waste?) )
list1.erase(it++);
else
++it;
}
8/01/2013
7/16/2013
Generating Mesh Shadows On Terrain Using OpenGL
Original post :
http://content.gpwiki.org/index.php/Generating_Mesh_Shadows_On_Terrain_Using_OpenGL
//
// complete function.
//
// unsigned char *lightmap
// int lightmapSize
// unsigned char shadowColor[3]
// float lightdir[3]
void MeshShadows(unsigned char *lightmap, int lightmapSize, unsigned char shadowColor[3], float lightDir[3]) { // variable initialization int lightmapChunkSize = 128; if(lightmapSize < lightmapChunkSize) lightmapChunkSize = lightmapSize; float terrainDivisions = lightmapSize / lightmapChunkSize; int terrainChunkSize = Terrain.size() / terrainDivisions; unsigned char *chunk = new unsigned char[(lightmapChunkSize)*(lightmapChunkSize)*3]; // create shadow texture GLuint shadowChunk; glGenTextures(1, &shadowChunk); glBindTexture(GL_TEXTURE_2D, shadowChunk); glEnable(GL_TEXTURE_2D); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, lightmapChunkSize, lightmapChunkSize, 0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); int terrainCol = 0; int terrainRow = 0; float x0 = 0; float y0 = 0; float x1 = terrainChunkSize; float y1 = terrainChunkSize; for(terrainRow = 0; terrainRow < terrainDivisions; terrainRow++) { for(terrainCol = 0; terrainCol < terrainDivisions; terrainCol++) { // setup orthogonal view glViewport(0, 0, terrainChunkSize * Terrain.size(), terrainChunkSize * Terrain.size()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, terrainChunkSize, 0, terrainChunkSize, -10000, 10000); glMatrixMode(GL_MODELVIEW); // apply light's direction to modelview matrix gluLookAt(lightDir[0], lightDir[1], lightDir[2], 0, 0, 0, 0, 1, 0); // loop through all vertices in terrain and find min and max points with respect to screen space float minX = 999999, maxX = -999999; float minY = 999999, maxY = -999999; double X, Y, Z; // get pointer to terrain vertices float *vertices = Terrain.vertices()->lock(); for(int i = y0-1; i < y1+1; i++) { if(i < 0) continue; for(int j = x0-1; j < x1+1; j++) { if(j < 0) continue; int index = i * Terrain.size() + j; // get screen coordinates for current vertex static GLint viewport[4]; static GLdouble modelview[16]; static GLdouble projection[16]; static GLfloat winX, winY, winZ; glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); glGetIntegerv( GL_VIEWPORT, viewport ); gluProject(vertices[index*3+0], vertices[index*3+1], vertices[index*3+2], modelview, projection, viewport, &X, &Y, &Z); if(X < minX) minX = X; if(X > maxX) maxX = X; if(Y < minY) minY = Y; if(Y > maxY) maxY = Y; } } // clear min and max values static float minX2, minY2, maxX2, maxY2; minX2 = minX; minY2 = minY; maxX2 = maxX; maxY2 = maxY; // clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, lightmapChunkSize, lightmapChunkSize); // orient viewport so that terrain chunk fits inside glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(minX, maxX, minY, maxY, -10000, 10000); glMatrixMode(GL_MODELVIEW); // apply light's direction vector to model view transformation glLoadIdentity(); gluLookAt(lightDir[0], lightDir[1], lightDir[2], 0, 0, 0, 0, 1, 0); // disable writing to the color buffer glColorMask(false, false, false, false); // render terrain Terrain.render(); // enable writing to the color buffer glColorMask(true, true, true, true); // render scene meshes '''BLACK''' RenderAllSceneMeshes(); // bind shadowChunk texture and copy frame buffer data glBindTexture(GL_TEXTURE_2D, shadowChunk); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, lightmapChunkSize, lightmapChunkSize); glBindTexture(GL_TEXTURE_2D, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, terrainChunkSize * Terrain.size(), terrainChunkSize * Terrain.size()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 0, terrainChunkSize, terrainChunkSize, -10000, 10000); glMatrixMode(GL_MODELVIEW); // rotate view so that xz plane becomes the xy plane glLoadIdentity(); glRotatef(90, 1, 0, 0); // reset max and min values minX = minY = 999999; maxX = maxY = -999999; glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); glGetIntegerv( GL_VIEWPORT, viewport ); // project each corner onto the screen // the corners are represented by the x0, y0, x1 and y1 values gluProject(x0, y0, modelview, projection, viewport, &X, &Y, &Z); if(X < minX) minX = X; if(X > maxX) maxX = X; if(Y < minY) minY = Y; if(Y > maxY) maxY = Y; gluProject(x1, y0, modelview, projection, viewport, &X, &Y, &Z); if(X < minX) minX = X; if(X > maxX) maxX = X; if(Y < minY) minY = Y; if(Y > maxY) maxY = Y; gluProject(x1, y1, modelview, projection, viewport, &X, &Y, &Z); if(X < minX) minX = X; if(X > maxX) maxX = X; if(Y < minY) minY = Y; if(Y > maxY) maxY = Y; gluProject(x0, y1, modelview, projection, viewport, &X, &Y, &Z); if(X < minX) minX = X; if(X > maxX) maxX = X; if(Y < minY) minY = Y; if(Y > maxY) maxY = Y; // resize and re-orient the viewport glViewport(0, 0, terrainChunkSize * Terrain.size(), terrainChunkSize * Terrain.size()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(minX, minY, maxX, maxY, -10000, 10000); glMatrixMode(GL_MODELVIEW); // rotate view so that xz plane becomes the xy plane glLoadIdentity(); glRotatef(90, 1, 0, 0); // setup projective texturing float PS[] = {1, 0, 0, 0}; float PT[] = {0, 1, 0, 0}; float PR[] = {0, 0, 1, 0}; float PQ[] = {0, 0, 0, 1}; glTexGenfv(GL_S, GL_EYE_PLANE, PS); glTexGenfv(GL_T, GL_EYE_PLANE, PT); glTexGenfv(GL_R, GL_EYE_PLANE, PR); glTexGenfv(GL_Q, GL_EYE_PLANE, PQ); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_GEN_Q); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); // setup texture matrix glBindTexture(GL_TEXTURE_2D, shadowChunk); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef(0.5, 0.5, 0); glScalef(0.5, 0.5, 1); glOrtho(minX2, maxX2, minY2, maxY2, -10000, 10000); gluLookAt(lightDir[0], lightDir[1], lightDir[2], 0, 0, 0, 0, 1, 0); glMatrixMode(GL_MODELVIEW); // render the terrain Terrain.render(); glBindTexture(GL_TEXTURE_2D, shadowChunk); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, lightmapChunkSize, lightmapChunkSize); // disable projective texturing glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_GEN_Q); // reset texture matrix glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); // get shadow texture data glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); for(int a = 0; a < lightmapChunkSize; a++) { for(int b = 0; b < lightmapChunkSize; b++) { int a2 = a + lightmapChunkSize * terrainRow; int b2 = b + lightmapChunkSize * terrainCol; lightmap[(a2 * lightmapSize + b2) * 3 + 0] = pixels[(a * lightmapChunkSize + b) * 3 + 0]; lightmap[(a2 * lightmapSize + b2) * 3 + 1] = pixels[(a * lightmapChunkSize + b) * 3 + 1]; lightmap[(a2 * lightmapSize + b2) * 3 + 2] = pixels[(a * lightmapChunkSize + b) * 3 + 2]; } } } } // increment which section on the terrain we are looking at x0 += terrainChunkSize; x1 += terrainChunkSize; } x0 = 0; x1 = terrainChunkSize; y0 += terrainChunkSize; y1 += terrainChunkSize; } // free memory glDeleteTextures(1, &shadowTexture); delete [] pixels; }
7/15/2013
google admob adView
1. https://kr.admob.com/
2. https://developers.google.com/mobile-ads-sdk/
3. bottom adView.
default center AdView, ignored android:gravity attribute
2. https://developers.google.com/mobile-ads-sdk/
3. bottom adView.
default center AdView, ignored android:gravity attribute
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adview"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxx"
android:gravity="bottom|center" >
7/12/2013
Hide JavaScript & CSS code - php
JavaScript 및 CSS 코드 은닉
지금까지 소스 숨기시려고 하신 분들, 보통 javascript로 return false 처리해서 막았습니다.
그러나 편집 -> 소스보기를 보거나 자바스크립트를 꺼버리면 무용지물이 되어버립니다..
따라서, 제가 고안한 방법!
PHP를 이용한 방법입니다.
스타일시트, style.css를 예제로 들어봅시다.
보통 style.css파일은 막지 못합니다. 따라서 이것을 php파일로 바꿔 코드를 숨길 수 있게 하는겁니다.
style.css파일이 다음과 같다고 합시다.
--------------------------------------------------------------------------------------------------
body {
font-size:11px;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
form {
padding:0px;
margin:0px;
}
td{
padding:2px;
}
img {
border:0px none;
}
/* General Links */
a {
font-size:11px;
font-weight:normal;
font-family:Verdana,Tahoma,Arial,sans-serif;
color:#777777;
text-decoration:none;
}
a:active {
font-size:11px;
font-weight:normal;
font-family:Verdana,Tahoma,Arial,sans-serif;
color:#777777;
text-decoration:none;
}
a:visited {
font-size:11px;
font-weight:normal;
font-family:Verdana,Tahoma,Arial,sans-serif;
color:#777777;
text-decoration:none;
}
a:hover {
font-size:11px;
font-weight:normal;
font-family:Verdana,Tahoma,Arial,sans-serif;
color:#DDDDDD;
text-decoration:underline;
}
/* General Horizontal Lines */
hr {height:1px;width:100%;color:#999999;background:#999999;border:0;}
--------------------------------------------------------------------------------------------------
그냥 보통 css파일입니다.. 따라서 아무것도 막지를 못하죠.
그러면 css파일을 style.php로 변경 한 후 다음과같이 해봅시다.
--------------------------------------------------------------------------------------------------
header("Content-type: text/css");
$load_check = $_GET['load_check'];
$_load_check = sha1(date('d m A s i'));
if($load_check == $_load_check){
?>
body {
font-size:11px;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
form {
padding:0px;
margin:0px;
}
td{
padding:2px;
}
img {
border:0px none;
}
/* General Links */
a {
font-size:11px;
font-weight:normal;
font-family:Verdana,Tahoma,Arial,sans-serif;
color:#777777;
text-decoration:none;
}
a:active {
font-size:11px;
font-weight:normal;
font-family:Verdana,Tahoma,Arial,sans-serif;
color:#777777;
text-decoration:none;
}
a:visited {
font-size:11px;
font-weight:normal;
font-family:Verdana,Tahoma,Arial,sans-serif;
color:#777777;
text-decoration:none;
}
a:hover {
font-size:11px;
font-weight:normal;
font-family:Verdana,Tahoma,Arial,sans-serif;
color:#DDDDDD;
text-decoration:underline;
}
/* General Horizontal Lines */
hr {height:1px;width:100%;color:#999999;background:#999999;border:0;}
}
else{
echo "/* 소스를 보시고 싶으시다면 연락해주세요.... admin@inera.net */";
}
?>
--------------------------------------------------------------------------------------------------
이렇게 변경 한 후 다음과 같이 css파일을 불러옵시다.
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
이렇게 하면 웹서버는 읽어와도 개인이 읽으려면 1초마다 바뀌는 해시값을 알아야 하기 때문에 보기가 힘들어집니다..
또한, 어떻게 암호화되었는지 모르면 거의 불가능하다고 보면 됩니다.
자바스크립트도 이와같이 처리하면 됩니다.
출처: zeroboard.com by Kay (http://flixey.com)
6/27/2013
Detect web browser language
$client_language=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
$find_str="KR";
$find_pos=strpos($client_language,$find_str);
if($find_pos==TRUE)
{
print("found ko");
}
else
{
print("not found ko");
}
?>
피드 구독하기:
덧글 (Atom)